@@ -8,7 +8,7 @@ LL | map["peter"].clear();
88help: to modify a `HashMap<&str, String>` use `.get_mut()`
99 |
1010LL - map["peter"].clear();
11- LL + if let Some(val) = map.get_mut("peter") { val.clear(); };
11+ LL + if let Some(val) = map.get_mut(& "peter") { val.clear(); };
1212 |
1313
1414error[E0594]: cannot assign to data in an index of `HashMap<&str, String>`
@@ -18,16 +18,20 @@ LL | map["peter"] = "0".to_string();
1818 | ^^^^^^^^^^^^ cannot assign
1919 |
2020 = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>`
21- help: use `.insert()` to insert a value into a `HashMap<&str, String>`, `.get_mut()` to modify it, or the entry API for more flexibility
21+ help: use `.insert()` to insert a value into a `HashMap<&str, String>`
2222 |
2323LL - map["peter"] = "0".to_string();
2424LL + map.insert("peter", "0".to_string());
2525 |
26+ help: use `.get_mut()` to modify an existing key in a `HashMap<&str, String>`
27+ |
2628LL - map["peter"] = "0".to_string();
27- LL + if let Some(val) = map.get_mut("peter") { *val = "0".to_string(); };
29+ LL + if let Some(val) = map.get_mut(&"peter") { *val = "0".to_string(); };
30+ |
31+ help: use the entry API to modify a `HashMap<&str, String>` for more flexibility
2832 |
2933LL - map["peter"] = "0".to_string();
30- LL + let val = map.entry("peter").or_insert ("0".to_string());
34+ LL + let val = map.entry("peter").insert_entry ("0".to_string());
3135 |
3236
3337error[E0596]: cannot borrow data in an index of `HashMap<&str, String>` as mutable
0 commit comments