18.5 Other Collection Types in the Standard Library

Besides Vec<T>, String, and HashMap<K, V>, Rust provides:

  • BTreeMap<K, V>: A balanced tree map keeping keys in sorted order. Offers O(log n) for inserts and lookups.
  • HashSet<T> / BTreeSet<T>: Store unique elements (hashed or sorted).
  • VecDeque<T>: A double-ended queue supporting efficient push/pop at both ends.
  • LinkedList<T>: A doubly linked list, efficient for inserting/removing at known nodes, but generally less cache-friendly than a vector.

All of these still follow Rust’s ownership and borrowing rules, so they are memory-safe by design.