3 ms·
Incidentally: for what that whole `match` block could be with the entry API: *example_map.entry("some_key").or_insert(0) += 1; Or, if you prefer an extra in
by chrismorgan 8y ago
Incidentally: for what that whole `match` block could be with the entry API:
*example_map.entry("some_key").or_insert(0) += 1;
Or, if you prefer an extra intermediate for clarity:
let entry = example_map.entry("some_key").or_insert(0);
*entry += 1;
This is a good example of how, often, Rust’s approach of having greater underlying complexity but exposing it sanely ends up allowing you to write something that is semantically superior and easier to reason about, while being faster too.
This and Rust’s ownership model (which I declare stands under the same banner) is the sort of thing that I regularly miss when working in JavaScript (and regularly missed when I used to work in Python plenty).