Crate arraydeque [] [src]

A circular buffer with fixed capacity. Requires Rust 1.20+

It can be stored directly on the stack if needed.

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

This crate is inspired by bluss/arrayvec

Feature Flags

The arraydeque crate has the following cargo feature flags:

  • std
    • Optional, enabled by default
    • Conversions between ArrayDeque and Vec
    • Use libstd

Usage

First, add the following to your Cargo.toml:

[dependencies]
arraydeque = "0.3"

Next, add this to your crate root:

extern crate arraydeque;

Currently arraydeque by default links to the standard library, but if you would instead like to use arraydeque in a #![no_std] situation or crate you can request this via:

[dependencies]
arraydeque = { version = "0.3", default-features = false }

Capacity

Note that the capacity() is always backend_array.len() - 1. Read more

Behaviors

ArrayDeque provides two different behaviors of pushing element when it's full, Saturating and Wrapping. The behavior is indicated by a marker type parameter of ArrayDeque, which defaults to Saturating.

Saturating

Pushing any element when ArrayDeque is full will directly return an Err(CapacityError) containing the element attempting to push, leaving the ArrayDeque unchanged.

use arraydeque::{ArrayDeque, Saturating, CapacityError};

let mut tester: ArrayDeque<[_; 3], Saturating> = ArrayDeque::new();

assert_eq!(tester.push_back(1), Ok(()));
assert_eq!(tester.push_back(2), Ok(()));
assert_eq!(tester.push_back(3), Err(CapacityError { element: 3 }));

Wrapping

Pushing any element when ArrayDeque is full will pop an element at the other side to spare room.

use arraydeque::{ArrayDeque, Wrapping};

let mut tester: ArrayDeque<[_; 3], Wrapping> = ArrayDeque::new();

assert_eq!(tester.push_back(1), None);
assert_eq!(tester.push_back(2), None);
assert_eq!(tester.push_back(3), Some(1));

Reexports

pub use behavior::Saturating;
pub use behavior::Wrapping;

Modules

behavior

Behavior semantics for ArrayDeque.

Structs

ArrayDeque

A fixed capacity ring buffer.

CapacityError

Error value indicating insufficient capacity

Drain

Draining ArrayDeque iterator

IntoIter

By-value ArrayDeque iterator

Iter

ArrayDeque iterator

IterMut

ArrayDeque mutable iterator

Traits

Array

Trait for fixed size arrays.

RangeArgument

IndexRange is implemented by Rust's built-in range types, produced by range syntax like .., a.., ..b or c..d.