about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonathan Turner <jonathandturner@users.noreply.github.com>2016-09-28 10:33:56 -0700
committerGitHub <noreply@github.com>2016-09-28 10:33:56 -0700
commit4676bb0172f378e192784f4f8ccdd367a40c97b4 (patch)
tree77df6322d452c02776f203086a50ea891b0f01a6
parentfe0729d2e48167d79848909f480066761a52f053 (diff)
parentf953d2564e2ebb79a20809c7cff85ccbcfc77d14 (diff)
downloadrust-4676bb0172f378e192784f4f8ccdd367a40c97b4.tar.gz
rust-4676bb0172f378e192784f4f8ccdd367a40c97b4.zip
Rollup merge of #36740 - frehberg:apidoc, r=steveklabnik
Document init of HashSet/HashMap from vector
-rw-r--r--src/libstd/collections/hash/map.rs16
-rw-r--r--src/libstd/collections/hash/set.rs14
2 files changed, 30 insertions, 0 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index 29a79631535..35f5641679a 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -335,6 +335,22 @@ fn test_resize_policy() {
 ///     println!("{:?} has {} hp", viking, health);
 /// }
 /// ```
+///
+/// A HashMap with fixed list of elements can be initialized from an array:
+///
+/// ```
+/// use std::collections::HashMap;
+///
+/// fn main() {
+///     let timber_resources: HashMap<&str, i32> =
+///     [("Norway", 100),
+///      ("Denmark", 50),
+///      ("Iceland", 10)]
+///      .iter().cloned().collect();
+///     // use the values stored in map
+/// }
+/// ```
+
 #[derive(Clone)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct HashMap<K, V, S = RandomState> {
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs
index a5089543980..cb8393ed075 100644
--- a/src/libstd/collections/hash/set.rs
+++ b/src/libstd/collections/hash/set.rs
@@ -98,6 +98,20 @@ use super::map::{self, HashMap, Keys, RandomState};
 ///     println!("{:?}", x);
 /// }
 /// ```
+///
+/// HashSet with fixed list of elements can be initialized from an array:
+///
+/// ```
+/// use std::collections::HashSet;
+///
+/// fn main() {
+///     let viking_names: HashSet<&str> =
+///         [ "Einar", "Olaf", "Harald" ].iter().cloned().collect();
+///     // use the values stored in the set
+/// }
+/// ```
+
+
 #[derive(Clone)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct HashSet<T, S = RandomState> {