behavior.rs |
Behavior semantics for `ArrayDeque`.
`ArrayDeque` provides two different behaviors, `Saturating` and `Wrapping`,
determining whether to remove existing element automatically when pushing
to a full deque.
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<_, 2, 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<_, 2, 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));
``` |
1602 |
error.rs |
|
741 |
lib.rs |
A circular buffer with fixed capacity.
Requires Rust 1.59+
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**](https://github.com/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`:
```toml
[dependencies]
arraydeque = "0.5"
```
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:
```toml
[dependencies]
arraydeque = { version = "0.4", default-features = false }
```
# Behaviors
`ArrayDeque` provides two different behaviors, `Saturating` and `Wrapping`,
determining whether to remove existing element automatically when pushing
to a full deque.
See the [behavior module documentation](behavior/index.html) for more. |
93758 |
range.rs |
|
931 |