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 the number of elements currently in the deque.

Clears the deque, removing all values.

Returns whether the deque is empty.

Returns whether the deque is full (i.e. if len() == capacity().

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

Appends an item to the front of the deque

Safety

This assumes the deque is not full.

Appends an item to the back of the deque

Safety

This assumes the deque is not full.

Returns an iterator over the deque.

Returns an iterator that allows modifying each value.

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

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

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

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

Performs the conversion.

Performs the conversion.

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.