mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-24 16:42:36 +02:00
Speaker Notes for hashmap.md (#295)
* Update hashmap.md * Update hashmap.md * Update hashmap.md * Update src/std/hashmap.md Co-authored-by: gendx <gendx@users.noreply.github.com> * Update hashmap.md * Wording --------- Co-authored-by: gendx <gendx@users.noreply.github.com> Co-authored-by: Andrew Walbran <qwandor@google.com>
This commit is contained in:
parent
c1e1963839
commit
faaf2eacdc
@ -35,6 +35,17 @@ fn main() {
|
||||
|
||||
<details>
|
||||
|
||||
* `HashMap` is not defined in the prelude and needs to be brought into scope.
|
||||
* Try the following lines of code. The first line will see if a book is in the hashmap and if not return an alternative value. The second line will insert the alternative value in the hashmap if the book is not found.
|
||||
|
||||
```rust,ignore
|
||||
let pc1 = page_counts
|
||||
.get("Harry Potter and the Sorcerer's Stone ")
|
||||
.unwrap_or(&336);
|
||||
let pc2 = page_counts
|
||||
.entry("The Hunger Games".to_string())
|
||||
.or_insert(374);
|
||||
```
|
||||
* Unlike `vec!`, there is unfortunately no standard `hashmap!` macro.
|
||||
|
||||
</details>
|
||||
|
Loading…
x
Reference in New Issue
Block a user