Rust Common Collections — VecDeque, LinkedList, HashSet, BTreeMap, and More
DodaTech
Updated 2026-06-28
1 min read
In this tutorial, you will learn about Rust Common Collections. We cover key concepts, practical examples, and best practices to help you master this topic.
Rust common collections beyond Vec include VecDeque for double-ended queues, LinkedList, HashSet, BTreeMap, and BinaryHeap for priority queues.
What You'll Learn
- VecDeque for queues
- HashSet for unique items
- BTreeMap for sorted maps
- BinaryHeap for priority queues
Why It Matters
Specialized collections improve performance. DodaZIP uses VecDeque for buffering and HashSet for deduplication.
Real-World Use
Task scheduling, deduplication, sorted data storage, priority-based processing.
use std::collections::{VecDeque, HashSet, BTreeMap, BinaryHeap, HashMap};
fn main() {
// VecDeque
let mut deque: VecDeque<i32> = VecDeque::new();
deque.push_back(1);
deque.push_front(0);
deque.push_back(2);
println!("Deque: {:?}", deque);
println!("Front: {:?}", deque.pop_front());
// HashSet
let mut set = HashSet::new();
set.insert(1);
set.insert(2);
set.insert(2); // Duplicate, ignored
println!("Set: {:?}", set);
println!("Contains 1: {}", set.contains(&1));
// BTreeMap (sorted by key)
let mut tree_map = BTreeMap::new();
tree_map.insert("b", 2);
tree_map.insert("a", 1);
tree_map.insert("c", 3);
for (key, value) in &tree_map {
println!("{}: {}", key, value);
}
// BinaryHeap (max-heap)
let mut heap = BinaryHeap::new();
heap.push(3);
heap.push(1);
heap.push(5);
heap.push(2);
println!("Max: {:?}", heap.pop());
println!("Next: {:?}", heap.pop());
}
← Previous
Rust Crates — Publishing and Using Crates from crates.io and Private Registries
Next →
Rust File I/O — Reading and Writing Files with std::fs and std::io
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro