diff --git a/src/std/hashmap.md b/src/std/hashmap.md index 15ff302a..db37a56f 100644 --- a/src/std/hashmap.md +++ b/src/std/hashmap.md @@ -35,6 +35,17 @@ fn main() {
+* `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.