Rollup merge of #36740 - frehberg:apidoc, r=steveklabnik

Document init of HashSet/HashMap from vector
This commit is contained in:
Jonathan Turner 2016-09-28 10:33:56 -07:00 committed by GitHub
commit 4676bb0172
2 changed files with 30 additions and 0 deletions

View File

@ -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> {

View File

@ -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> {