pub type Deque<T, const N: usize> = DequeInner<T, OwnedVecStorage<T, N>>;
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);
}
Aliased Type§
pub struct Deque<T, const N: usize> { /* private fields */ }
Implementations§
Source§impl<T, const N: usize> Deque<T, N>
impl<T, const N: usize> Deque<T, N>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
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();
Sourcepub const fn capacity(&self) -> usize
pub const fn capacity(&self) -> usize
Returns the maximum number of elements the deque can hold.
This method is not available on a DequeView
, use storage_capacity
instead.
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of elements currently in the deque.
This method is not available on a DequeView
, use storage_len
instead.