When you need to look things up by key rather than position, you reach for a map. Rust's workhorse is HashMap<K, V>, with BTreeMap as the sorted alternative.
HashMap basics
HashMap<K, V> stores key-value pairs with average O(1) lookup. insert adds or replaces; get returns an Option<&V> — the key might be absent, so Option appears again. Keys must be hashable and comparable, which most standard types are out of the box.
The entry API
The killer feature is entry: map.entry(key).or_insert(0) gives you a mutable reference to the value, inserting a default if the key is missing. It's the clean way to do 'increment a counter' or 'append to a list per key' without a get-check-insert dance. entry is one of the most-loved methods in the standard library.
*map.entry(word).or_insert(0) += 1; handles both 'first time seen' and 'seen before' in one line and one lookup. Reaching for a manual if contains_key check is the beginner tell — it does two lookups and reads worse.HashMap vs BTreeMap
HashMap is unordered and fast. BTreeMap keeps keys sorted (so iteration is in order) at a small lookup cost. Choose HashMap by default; reach for BTreeMap when you need sorted iteration or range queries. Same API shape, different ordering guarantee.