about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-12-28 06:52:15 +0000
committerbors <bors@rust-lang.org>2018-12-28 06:52:15 +0000
commitee49bf8964492ad22f530cbcadcafc6704ec44c3 (patch)
treea0ce7dd6363ddd204cc58731aed97471330e5d1e
parente8ca35e63dda82a8b5fa8eb72cf3e490a5794a46 (diff)
parentadfc0667bc0e452aed0f5e65452c00f775b48ef4 (diff)
Auto merge of #55519 - fhartwig:hashmap-index-example, r=Centril
Add example of using the indexing operator to HashMap docs

Fixes #52575
-rw-r--r--src/liballoc/collections/btree/map.rs3
-rw-r--r--src/libstd/collections/hash/map.rs3
2 files changed, 6 insertions, 0 deletions
diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs
index 0998fafa245..717650aca96 100644
--- a/src/liballoc/collections/btree/map.rs
+++ b/src/liballoc/collections/btree/map.rs
@@ -87,6 +87,9 @@ use self::Entry::*;
 ///     }
 /// }
 ///
+/// // Look up the value for a key (will panic if the key is not found).
+/// println!("Movie review: {}", movie_reviews["Office Space"]);
+///
 /// // iterate over everything.
 /// for (movie, review) in &movie_reviews {
 ///     println!("{}: \"{}\"", movie, review);
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index 86a8e0f5baf..91c4e990e00 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -309,6 +309,9 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
 ///     }
 /// }
 ///
+/// // Look up the value for a key (will panic if the key is not found).
+/// println!("Review for Jane: {}", book_reviews["Pride and Prejudice"]);
+///
 /// // Iterate over everything.
 /// for (book, review) in &book_reviews {
 ///     println!("{}: \"{}\"", book, review);