Deque

Type Alias Deque 

Source
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>

Source

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();
Source

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.

Source

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.

Trait Implementations§

Source§

impl<T, const N: usize> Clone for Deque<T, N>
where T: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, const N: usize> Default for Deque<T, N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, const N: usize> IntoIterator for Deque<T, N>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, N>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq, const N: usize> PartialEq for Deque<T, N>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq, const N: usize> Eq for Deque<T, N>