Struct heapless::Deque [−][src]
pub struct Deque<T, const N: usize> { /* fields omitted */ }
Expand description
A fixed capacity double-ended queue.
Examples
use heapless::Deque;
// A deque with a fixed capacity of 8 elements allocated on the stack
let mut deque = Deque::<_, 8>::new();
// You can use it as a good old FIFO queue.
deque.push_back(1);
deque.push_back(2);
assert_eq!(deque.len(), 2);
assert_eq!(deque.pop_front(), Some(1));
assert_eq!(deque.pop_front(), Some(2));
assert_eq!(deque.len(), 0);
// Deque is double-ended, you can push and pop from the front and back.
deque.push_back(1);
deque.push_front(2);
deque.push_back(3);
deque.push_front(4);
assert_eq!(deque.pop_front(), Some(4));
assert_eq!(deque.pop_front(), Some(2));
assert_eq!(deque.pop_front(), Some(1));
assert_eq!(deque.pop_front(), Some(3));
// You can iterate it, yielding all the elements front-to-back.
for x in &deque {
println!("{}", x);
}
Implementations
Constructs a new, empty deque with a fixed capacity of N
Examples
use heapless::Deque;
// allocate the deque on the stack
let mut x: Deque<u8, 16> = Deque::new();
// allocate the deque in a static variable
static mut X: Deque<u8, 16> = Deque::new();
Returns the maximum number of elements the deque can hold.
Returns a pair of slices which contain, in order, the contents of the Deque
.
Returns a pair of mutable slices which contain, in order, the contents of the Deque
.
Provides a reference to the front element, or None if the Deque
is empty.
Provides a mutable reference to the front element, or None if the Deque
is empty.
Provides a reference to the back element, or None if the Deque
is empty.
Provides a mutable reference to the back element, or None if the Deque
is empty.
Removes the item from the front of the deque and returns it, or None
if it’s empty
Removes the item from the back of the deque and returns it, or None
if it’s empty
Appends an item
to the front of the deque
Returns back the item
if the deque is full
Appends an item
to the back of the deque
Returns back the item
if the deque is full