Skip to content

Commit a380bee

Browse files
Rollup merge of rust-lang#55519 - fhartwig:hashmap-index-example, r=frewsxcv
Add example of using the indexing operator to HashMap docs Fixes rust-lang#52575
2 parents 06722f9 + 4bddb76 commit a380bee

File tree

2 files changed

+6
-0
lines changed
  • src
    • liballoc/collections/btree
    • libstd/collections/hash

2 files changed

+6
-0
lines changed

src/liballoc/collections/btree/map.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ use self::Entry::*;
9797
/// }
9898
/// }
9999
///
100+
/// // Look up the value for a key (will panic if the key is not found).
101+
/// println!("Review for Jane: {}", book_reviews["Pride and Prejudice"]);
102+
///
100103
/// // iterate over everything.
101104
/// for (movie, review) in &movie_reviews {
102105
/// println!("{}: \"{}\"", movie, review);

src/libstd/collections/hash/map.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
318318
/// }
319319
/// }
320320
///
321+
/// // Look up the value for a key (will panic if the key is not found).
322+
/// println!("Review for Jane: {}", book_reviews["Pride and Prejudice"]);
323+
///
321324
/// // Iterate over everything.
322325
/// for (book, review) in &book_reviews {
323326
/// println!("{}: \"{}\"", book, review);

0 commit comments

Comments
 (0)