Consumer

Struct Consumer 

Source
pub struct Consumer<T> { /* private fields */ }
Expand description

The consumer half of an SPSC ring buffer.

Use pop to remove elements. Takes &mut self to statically ensure single-consumer access.

Implementations§

Source§

impl<T> Consumer<T>

Source

pub fn pop(&mut self) -> Option<T>

Attempts to pop a value from the ring buffer.

Returns Some(value) if data is available, None if the buffer is empty. Values are returned in FIFO order.

§Example
use nexus_queue;

let (mut producer, mut consumer) = nexus_queue::ring_buffer::<u32>(8);

assert_eq!(consumer.pop(), None); // Empty

producer.push(42).unwrap();
assert_eq!(consumer.pop(), Some(42));
Source

pub const fn capacity(&self) -> usize

Returns the capacity of the ring buffer.

Source

pub fn is_disconnected(&self) -> bool

Returns true if the producer has been dropped.

Trait Implementations§

Source§

impl<T> Debug for Consumer<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Send> Send for Consumer<T>

Auto Trait Implementations§

§

impl<T> Freeze for Consumer<T>

§

impl<T> !RefUnwindSafe for Consumer<T>

§

impl<T> !Sync for Consumer<T>

§

impl<T> Unpin for Consumer<T>

§

impl<T> !UnwindSafe for Consumer<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.