The type HashMap<K, V> stores a mapping of keys of type K to values
of type V. It does this via a hashing function, which determines how
it places these keys and values into memory. Many programming languages
support this kind of data structure, but they often use a different
name, such as hash, map, object, hash table, dictionary, or associative
array, just to name a few.
Creating a New Hash Maps
collect
Another way of constructing a hash map is by using iterators and the
collect
method on a vector of tuples, where each tuple consists of a key and its
value.
Ownership
For types that implement the Copy trait, like i32, the values are
copied into the hash map. For owned values like String, the values
will be moved and the hash map will be the owner of those values: