Skip to content

Commit ee49bf8

Browse files
committed
Auto merge of #55519 - fhartwig:hashmap-index-example, r=Centril
Add example of using the indexing operator to HashMap docs Fixes #52575
2 parents e8ca35e + adfc066 commit ee49bf8

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

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ use self::Entry::*;
8787
/// }
8888
/// }
8989
///
90+
/// // Look up the value for a key (will panic if the key is not found).
91+
/// println!("Movie review: {}", movie_reviews["Office Space"]);
92+
///
9093
/// // iterate over everything.
9194
/// for (movie, review) in &movie_reviews {
9295
/// println!("{}: \"{}\"", movie, review);

src/libstd/collections/hash/map.rs

+3
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
309309
/// }
310310
/// }
311311
///
312+
/// // Look up the value for a key (will panic if the key is not found).
313+
/// println!("Review for Jane: {}", book_reviews["Pride and Prejudice"]);
314+
///
312315
/// // Iterate over everything.
313316
/// for (book, review) in &book_reviews {
314317
/// println!("{}: \"{}\"", book, review);

0 commit comments

Comments
 (0)