#vec-deque #fixed-size #deque

fixed_deque

A fixed size VecDeque to match Python Deque

8 stable releases

Uses new Rust 2024

1.6.0 Jan 29, 2026
1.5.0 Jan 28, 2026
1.4.0 Sep 26, 2025
1.3.0 Dec 21, 2024
0.1.0 Sep 18, 2024

#315 in Data structures

Download history 83/week @ 2025-10-16 87/week @ 2025-10-23 39/week @ 2025-10-30 100/week @ 2025-11-06 8/week @ 2025-11-13 9/week @ 2025-11-20 19/week @ 2025-11-27 124/week @ 2025-12-04 34/week @ 2025-12-11 23/week @ 2025-12-18 19/week @ 2025-12-25 73/week @ 2026-01-01 23/week @ 2026-01-08 62/week @ 2026-01-15 38/week @ 2026-01-22 34/week @ 2026-01-29

168 downloads per month
Used in 7 crates (2 directly)

MIT license

105KB
2K SLoC

Deque

Crates.io Version Documentation

A fixed size VecDeque for Rust to match the Python Deque functionality.

Implemented as a thin wrapper around std::collections::VecDeque with custom handling for push_back and push_front that prevents the VecDeque from growing past the set maximum length.

Once the deque is full, when a new item is pushed to the deque, an element from the opposite end is popped and returned.

use fixed_deque::Deque;

let mut deque: Deque<i32> = Deque::new(3);
deque.push_back(1);
deque.push_back(2);
deque.push_back(3);
deque.push_back(4);
assert_eq!(deque.len(), 3);
assert_eq!(deque.maxlen(), 3);
assert_eq!(deque.get(0), Some(&2));

let mut deque = Deque::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0], 5);
assert_eq!(deque.len(), 5);
let popped = deque.push_back(6.0);
assert_eq!(popped, Some(1.0));
assert_eq!(deque.len(), 5);

let mut deque: Deque<&str> = (vec!["a", "b", "c"], 5).into();
assert_eq!(deque.len(), 3);
assert_eq!(deque.maxlen(), 5);
assert_eq!(deque.front(), Some(&"a"));
deque.push_front("1");
deque.push_front("2");
deque.push_front("3");
assert_eq!(deque.front(), Some(&"3"));
assert_eq!(deque.back(), Some(&"b"));

Features

Optional serde feature that adds support for (de)serializing the Deque.

cargo add fixed_deque --features serde

Contribution

Contributions are very welcome. If you feel something could be added or improved, please do open a PR.

  • Always add test cases for new functionality
  • Ensure that code is formatted with cargo fmt and cargo clippy --all-features passes

License

MIT

Dependencies

~0–280KB