mirror of
https://github.com/ArthurDanjou/exercism-rust.git
synced 2026-01-29 03:10:33 +01:00
715 B
715 B
Hints
General
-
Upon fetching an entry using the
entrymethod, the entry can be modified in-place after dereferencing it. -
The
or_insertmethod inserts the given value in the case when the entry is vacant, and returns a mutable reference to the value in the entry.
*counter.entry(key).or_insert(0) += 1;
- The
or_defaultmethod ensures a value is in the entry by inserting the default value if empty, and returns a mutable reference to the value in the entry.
*counter.entry(key).or_default() += 1;