pub struct SpscRing<T>(/* private fields */);Expand description
Wait-free single-producer single-consumer ring buffer for audio samples.
SpscRing::channel hands back the two halves, the way mpsc::channel does. Each half is Send but not
Sync, so the “exactly one producer, exactly one consumer” rule that a
ring like this depends on is enforced by the type system instead of by a
comment: the producer moves to the capture thread, the consumer to the
playback thread, and neither can be shared.
Backed by [rtrb] (the ring used across the Rust audio ecosystem):
no allocation after construction, no locks, no unsafe in this crate.
use gemini_genai_rs::buffer::SpscRing;
let (mut tx, mut rx) = SpscRing::<i16>::channel(1024);
assert_eq!(tx.write(&[1, 2, 3]), 3);
let mut out = [0i16; 8];
assert_eq!(rx.read(&mut out), 3);
assert_eq!(&out[..3], &[1, 2, 3]);Implementations§
Source§impl<T: Copy> SpscRing<T>
impl<T: Copy> SpscRing<T>
Sourcepub fn channel(capacity: usize) -> (SpscProducer<T>, SpscConsumer<T>)
pub fn channel(capacity: usize) -> (SpscProducer<T>, SpscConsumer<T>)
Create a ring holding exactly capacity samples and split it into its
producer and consumer halves.
§Panics
Panics if capacity is 0.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for SpscRing<T>
impl<T> RefUnwindSafe for SpscRing<T>where
T: RefUnwindSafe,
impl<T> Send for SpscRing<T>where
T: Send,
impl<T> Sync for SpscRing<T>where
T: Sync,
impl<T> Unpin for SpscRing<T>where
T: Unpin,
impl<T> UnwindSafe for SpscRing<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].