pub struct Consumer<'a, T, const N: usize> { /* private fields */ }
Expand description
A queue “consumer”; it can dequeue items from the queue
NOTE the consumer semantically owns the head
pointer of the queue
Implementations§
source§impl<'a, T, const N: usize> Consumer<'a, T, N>
impl<'a, T, const N: usize> Consumer<'a, T, N>
sourcepub fn dequeue(&mut self) -> Option<T>
pub fn dequeue(&mut self) -> Option<T>
Returns the item in the front of the queue, or None
if the queue is empty
sourcepub unsafe fn dequeue_unchecked(&mut self) -> T
pub unsafe fn dequeue_unchecked(&mut self) -> T
Returns the item in the front of the queue, without checking if there are elements in the queue
See Queue::dequeue_unchecked
for safety
sourcepub fn ready(&self) -> bool
pub fn ready(&self) -> bool
Returns if there are any items to dequeue. When this returns true
, at least the
first subsequent dequeue will succeed
sourcepub fn peek(&self) -> Option<&T>
pub fn peek(&self) -> Option<&T>
Returns the item in the front of the queue without dequeuing, or None
if the queue is
empty
§Examples
use heapless::spsc::Queue;
let mut queue: Queue<u8, 235> = Queue::new();
let (mut producer, mut consumer) = queue.split();
assert_eq!(None, consumer.peek());
producer.enqueue(1);
assert_eq!(Some(&1), consumer.peek());
assert_eq!(Some(1), consumer.dequeue());
assert_eq!(None, consumer.peek());
Trait Implementations§
Auto Trait Implementations§
impl<'a, T, const N: usize> Freeze for Consumer<'a, T, N>
impl<'a, T, const N: usize> !RefUnwindSafe for Consumer<'a, T, N>
impl<'a, T, const N: usize> !Sync for Consumer<'a, T, N>
impl<'a, T, const N: usize> Unpin for Consumer<'a, T, N>
impl<'a, T, const N: usize> !UnwindSafe for Consumer<'a, T, N>
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