Closed
Description
The following is invalid
let mut unique_things: HashMap<usize, bool> = HashMap::new();
unique_things[&5] = false;
error[E0594]: cannot assign to data in an index of `HashMap<usize, bool>`
--> src/main.rs:147:2
|
147 | unique_things[&5] = false;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign
|
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<usize, bool>`
Because the entry &5
must exist before it can be assigned to. We should propose the use of the Entry
APIs or .insert
method.