pub struct Queue<T, const N: usize> { /* private fields */ }
Expand description

A statically allocated single producer single consumer queue with a capacity of N - 1 elements

IMPORTANT: To get better performance use a value for N that is a power of 2 (e.g. 16, 32, etc.).

Implementations

Creates an empty queue with a fixed capacity of N - 1

Returns the maximum number of elements the queue can hold

Returns the number of elements in the queue

Returns true if the queue is empty

Returns true if the queue is full

Iterates from the front of the queue to the back

Returns an iterator that allows modifying each value

Adds an item to the end of the queue

Returns back the item if the queue is full

Returns the item in the front of the queue, or None if the queue is empty

Returns a reference to 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());

Adds an item to the end of the queue, without checking if it’s full

Unsafety

If the queue is full this operation will leak a value (T’s destructor won’t run on the value that got overwritten by item), and will allow the dequeue operation to create a copy of item, which could result in T’s destructor running on item twice.

Returns the item in the front of the queue, without checking if there is something in the queue

Unsafety

If the queue is empty this operation will return uninitialized memory.

Splits a queue into producer and consumer endpoints

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Executes the destructor for this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
Feeds this value into the given Hasher.
Feeds a slice of this type into the given Hasher.
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.