@@ -276,17 +276,31 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
276
276
/// ```
277
277
/// use std::collections::HashMap;
278
278
///
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).
281
281
/// let mut book_reviews = HashMap::new();
282
282
///
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
+ /// );
288
300
///
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).
290
304
/// if !book_reviews.contains_key("Les Misérables") {
291
305
/// println!("We've got {} reviews, but Les Misérables ain't one.",
292
306
/// book_reviews.len());
@@ -295,16 +309,16 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
295
309
/// // oops, this review has a lot of spelling mistakes, let's delete it.
296
310
/// book_reviews.remove("The Adventures of Sherlock Holmes");
297
311
///
298
- /// // look up the values associated with some keys.
312
+ /// // Look up the values associated with some keys.
299
313
/// let to_find = ["Pride and Prejudice", "Alice's Adventure in Wonderland"];
300
- /// for book in &to_find {
314
+ /// for & book in &to_find {
301
315
/// match book_reviews.get(book) {
302
316
/// Some(review) => println!("{}: {}", book, review),
303
317
/// None => println!("{} is unreviewed.", book)
304
318
/// }
305
319
/// }
306
320
///
307
- /// // iterate over everything.
321
+ /// // Iterate over everything.
308
322
/// for (book, review) in &book_reviews {
309
323
/// println!("{}: \"{}\"", book, review);
310
324
/// }
0 commit comments