Skip to content

Commit

Permalink
std: Add example for HashMap::entry()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrik Sverdrup committed May 9, 2015
1 parent 6cd7486 commit 1e9ce0d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libstd/collections/hash/map.rs
Expand Up @@ -916,6 +916,24 @@ impl<K, V, S> HashMap<K, V, S>
}

/// Gets the given key's corresponding entry in the map for in-place manipulation.
///
/// # Examples
///
/// ```
/// use std::collections::HashMap;
///
/// let mut letters = HashMap::new();
///
/// for ch in "a short treatise on fungi".chars() {
/// let counter = letters.entry(ch).or_insert(0);
/// *counter += 1;
/// }
///
/// assert_eq!(letters[&'s'], 2);
/// assert_eq!(letters[&'t'], 3);
/// assert_eq!(letters[&'u'], 1);
/// assert_eq!(letters.get(&'y'), None);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn entry(&mut self, key: K) -> Entry<K, V> {
// Gotta resize now.
Expand Down

0 comments on commit 1e9ce0d

Please sign in to comment.