pub struct Buffer<const N: usize> { /* private fields */ }Expand description
A Buffer<N> consists of a [u8; N] array along with two usize
indices into the array. N must be a power of two. (If you need more
flexibility with sizing, consider using a bbqueue::BBBuffer instead.)
A Buffer<N> can hold N bytes of data and guarantees FIFO ordering.
The only way to use a Buffer is to split it into a Producer and a
Consumer, which may then be passed to different threads or contexts.
Implementations§
Source§impl<const N: usize> Buffer<N>
impl<const N: usize> Buffer<N>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Return a new, empty buffer. The memory backing the buffer is zero-initialized.
Sourcepub fn split(&mut self) -> (Producer<'_, N>, Consumer<'_, N>)
pub fn split(&mut self) -> (Producer<'_, N>, Consumer<'_, N>)
Split the Buffer into a Producer and a Consumer. This function is the
only safe way to create a Producer or a Consumer. This function requires
a mutable (i.e. exclusive) reference to the buffer, and the lifetime of that
reference is equal to the lifetimes of the producer and consumer which are
returned. Therefore, for a given buffer, only one producer and one consumer
can exist at one time.
Trait Implementations§
impl<const N: usize> Send for Buffer<N>
impl<const N: usize> Sync for Buffer<N>
Buffer<N> is Send and Sync because accesses to its internal data are
only possible via a single Producer and a single Consumer at any time.