This is a loose summary of the Rust std::collections
documentation formatted for personal reference. Rust offers a range of collection types for different use cases. Reading through the lines in the documentation the underlying theme is the following:
Starting with
Vec
orHashMap
is almost always good enough until you know more about your performance and needs.
Collection | Description | Use |
---|---|---|
Vec | A continuous array. Similar to a Python List | - Resizable, heap allocated array or stack. - Item properties unimportant - Append to end of in order sequence |
VecDeque | A double ended growable queue | - Insertion at front end back of sequence. - Otherwise same use properties as Vec |
LinkedList | A doubly linked list | - Efficient split and append of lists - Avoid amortisation of Vec and VecDeque |
HashMap | Similar to Python Dictionary | - Associate keys with values i.e. a cache |
BTreeMap | An ordered HashMap . | - Need key value pairs with functionality for range slicing, get largest/smallest, and filtering |
HashSet | Similar to Python Dictionary with only Hashed keys. | - Hold unique keys i.e. values seen before |
BTreeSet | An ordered HashSet . | - Need unique keys with functionality for range slicing, get largest/smallest, and filtering |
BinaryHeap | A max value priority queue. | - Storing largest or highest priority item i.e. a scheduler |