@@ -276,17 +276,31 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
276276/// ```
277277/// use std::collections::HashMap;
278278///
279- /// // type inference lets us omit an explicit type signature (which
280- /// // would be `HashMap<&str, &str >` in this example).
279+ /// // Type inference lets us omit an explicit type signature (which
280+ /// // would be `HashMap<String, String >` in this example).
281281/// let mut book_reviews = HashMap::new();
282282///
283- /// // review some books.
284- /// book_reviews.insert("Adventures of Huckleberry Finn", "My favorite book.");
285- /// book_reviews.insert("Grimms' Fairy Tales", "Masterpiece.");
286- /// book_reviews.insert("Pride and Prejudice", "Very enjoyable.");
287- /// book_reviews.insert("The Adventures of Sherlock Holmes", "Eye lyked it alot.");
283+ /// // Review some books.
284+ /// book_reviews.insert(
285+ /// "Adventures of Huckleberry Finn".to_string(),
286+ /// "My favorite book.".to_string(),
287+ /// );
288+ /// book_reviews.insert(
289+ /// "Grimms' Fairy Tales".to_string(),
290+ /// "Masterpiece.".to_string(),
291+ /// );
292+ /// book_reviews.insert(
293+ /// "Pride and Prejudice".to_string(),
294+ /// "Very enjoyable.".to_string(),
295+ /// );
296+ /// book_reviews.insert(
297+ /// "The Adventures of Sherlock Holmes".to_string(),
298+ /// "Eye lyked it alot.".to_string(),
299+ /// );
288300///
289- /// // check for a specific one.
301+ /// // Check for a specific one.
302+ /// // When collections store owned values (String), they can still be
303+ /// // queried using references (&str).
290304/// if !book_reviews.contains_key("Les Misérables") {
291305/// println!("We've got {} reviews, but Les Misérables ain't one.",
292306/// book_reviews.len());
@@ -295,16 +309,16 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
295309/// // oops, this review has a lot of spelling mistakes, let's delete it.
296310/// book_reviews.remove("The Adventures of Sherlock Holmes");
297311///
298- /// // look up the values associated with some keys.
312+ /// // Look up the values associated with some keys.
299313/// let to_find = ["Pride and Prejudice", "Alice's Adventure in Wonderland"];
300- /// for book in &to_find {
314+ /// for & book in &to_find {
301315/// match book_reviews.get(book) {
302316/// Some(review) => println!("{}: {}", book, review),
303317/// None => println!("{} is unreviewed.", book)
304318/// }
305319/// }
306320///
307- /// // iterate over everything.
321+ /// // Iterate over everything.
308322/// for (book, review) in &book_reviews {
309323/// println!("{}: \"{}\"", book, review);
310324/// }
0 commit comments