Add doc example to HashMap::hasher

This commit is contained in:
Ethan Dagner 2017-09-23 11:47:21 -06:00
parent a83c3e7771
commit bc43e17392

View File

@ -691,6 +691,17 @@ impl<K, V, S> HashMap<K, V, S>
/// Returns a reference to the map's [`BuildHasher`]. /// Returns a reference to the map's [`BuildHasher`].
/// ///
/// [`BuildHasher`]: ../../std/hash/trait.BuildHasher.html /// [`BuildHasher`]: ../../std/hash/trait.BuildHasher.html
///
/// # Examples
///
/// ```
/// use std::collections::HashMap;
/// use std::collections::hash_map::RandomState;
///
/// let hasher = RandomState::new();
/// let map: HashMap<isize, isize> = HashMap::with_hasher(hasher);
/// let hasher: &RandomState = map.hasher();
/// ```
#[stable(feature = "hashmap_public_hasher", since = "1.9.0")] #[stable(feature = "hashmap_public_hasher", since = "1.9.0")]
pub fn hasher(&self) -> &S { pub fn hasher(&self) -> &S {
&self.hash_builder &self.hash_builder