On this page
VecDeque
Prev: `BTreeMap` | Up: collections | Next: `BinaryHeap`
Rel: collections, rust/builtins
Ref: Rust std — VecDeque
Tags: #public #prog #rust #stdlib #collections #tier/standard
Signature & Overview
VecDeque<T>
Double-ended growable ring buffer with $O(1)$ push_front/pop_front/push_back.
Notes & Pitfalls
- $O(1)$ push/pop at BOTH ends: Ring buffer ideal for FIFO queues and sliding windows (unlike
Vec::remove(0)which is $O(n)$). - Non-contiguous internally: Call
.make_contiguous()if you need a single&[T]slice.
Example
use std::collections::VecDeque;
fn main() {
let mut q = VecDeque::from(["first", "second"]);
q.push_back("third");
assert_eq!(q.pop_front(), Some("first"));
assert_eq!(q.front(), Some(&"second"));
}
Linked from
Related notes
- tuts/rust/std/collections/BinaryHeap Linked here; links to this page; shared tags: #collections, #prog, #rust, #stdlib, #tier
- tuts/rust/std/collections/BTreeMap Linked here; links to this page; shared tags: #collections, #prog, #rust, #stdlib, #tier
- tuts/rust/std/collections Linked here; links to this page; shared tags: #collections, #prog, #rust, #stdlib
- tuts/rust/builtins Linked here; shared tags: #prog, #rust
- tuts/rust/std/collections/HashMap shared tags: #collections, #prog, #rust, #stdlib, #tier
- tuts/rust/std/collections/HashSet shared tags: #collections, #prog, #rust, #stdlib, #tier
- tuts/rust/std/error_and_fmt/Display shared tags: #prog, #rust, #stdlib, #tier
- tuts/rust/std/error_and_fmt/Error shared tags: #prog, #rust, #stdlib, #tier
- tuts/rust/std/error_and_fmt/format shared tags: #prog, #rust, #stdlib, #tier
- tuts/rust/std/ffi/CString shared tags: #prog, #rust, #stdlib, #tier