DequeView

Type Alias DequeView 

Source
pub type DequeView<T> = DequeInner<T, ViewVecStorage<T>>;
Expand description

A double-ended queue with dynamic capacity.

§Examples

use heapless::deque::{Deque, DequeView};

// A deque with a fixed capacity of 8 elements allocated on the stack
let mut deque_buf = Deque::<_, 8>::new();

// A DequeView can be obtained through unsized coercion of a `Deque`
let deque: &mut DequeView<_> = &mut deque_buf;

// You can use it as a good old FIFO queue.
deque.push_back(1);
deque.push_back(2);
assert_eq!(deque.storage_len(), 2);

assert_eq!(deque.pop_front(), Some(1));
assert_eq!(deque.pop_front(), Some(2));
assert_eq!(deque.storage_len(), 0);

// DequeView 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 DequeView<T> { /* private fields */ }