Crate fixed_vec_deque

source ·
Expand description

A double-ended queue implemented with a fixed ring buffer.

This queue has O(1) amortized inserts and removals from both ends of the container. It also has O(1) indexing like a vector. The contained elements are not required to be copyable, and the queue will be sendable if the contained type is sendable.

The size of the FixedVecDeque must be completely specified at construction time, like this:

use fixed_vec_deque::FixedVecDeque;

let _ = FixedVecDeque::<[Foo; 4]>::new();

#[derive(Default)]
struct Foo;

Modifications can only happen in-place, this means that items stored in the queue must always implement Default.

push_back and push_front don’t take an argument, instead they return a mutable reference so that the newly inserted element is mutated in-place:

use fixed_vec_deque::FixedVecDeque;

let mut buf = FixedVecDeque::<[Foo; 4]>::new();
buf.push_back().data = 42;

#[derive(Default)]
struct Foo {
    data: u32,
}

On a similar note, pop_front and pop_back returns references instead of moving the elements.

A consequence of this is that this structure never modifies the data it contains, even if it has been popped.

Structs

A double-ended queue implemented with a fixed buffer.

Traits

Types that can be used as the backing store for a FixedVecDeque.