pub struct Consumer<'a, T> { /* private fields */ }Expand description
A consumer; it can dequeue items from the queue.
Note: The consumer semantically owns the head pointer of the queue.
Implementations§
Source§impl<T> Consumer<'_, T>
impl<T> Consumer<'_, T>
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.
§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 is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether 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!(consumer.is_empty());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());