pub struct Producer<T> { /* private fields */ }Expand description
The producer half of an SPSC ring buffer.
Takes &mut self to statically ensure single-producer access.
Implementations§
Source§impl<T> Producer<T>
impl<T> Producer<T>
Sourcepub fn push(&mut self, value: T) -> Result<(), Full<T>>
pub fn push(&mut self, value: T) -> Result<(), Full<T>>
Attempts to push a value into the ring buffer.
Returns Err(Full(value)) if the buffer is full, giving the value back.
§Example
use nexus_queue;
let (mut producer, mut consumer) = nexus_queue::ring_buffer::<u32>(2);
assert!(producer.push(1).is_ok());
assert!(producer.push(2).is_ok());
assert!(producer.push(3).is_err()); // FullSourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Returns true if the consumer has been dropped.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Producer<T>
impl<T> !RefUnwindSafe for Producer<T>
impl<T> !Sync for Producer<T>
impl<T> Unpin for Producer<T>
impl<T> !UnwindSafe for Producer<T>
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