about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-06-02 09:16:40 -0700
committerbors <bors@rust-lang.org>2013-06-02 09:16:40 -0700
commit077ca799418b291f45ccba072aedab4daeace057 (patch)
treebffadaae8f6387119b82050bc14ec493df27c169 /src/libstd
parentc354a0c7eb22f7a4bc1c7adf8e2ed34ee96428aa (diff)
parentd443fc6d90577003724ce128d2c07b7ad6b347c9 (diff)
downloadrust-077ca799418b291f45ccba072aedab4daeace057.tar.gz
rust-077ca799418b291f45ccba072aedab4daeace057.zip
auto merge of #6867 : Dretch/rust/hashmap_get_mut, r=nikomatsakis
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/hashmap.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs
index fb4cab72126..b1400d1bc76 100644
--- a/src/libstd/hashmap.rs
+++ b/src/libstd/hashmap.rs
@@ -501,6 +501,15 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
         }
     }
 
+    /// Retrieves a (mutable) value for the given key, failing if the key
+    /// is not present.
+    pub fn get_mut<'a>(&'a mut self, k: &K) -> &'a mut V {
+        match self.find_mut(k) {
+            Some(v) => v,
+            None => fail!("No entry found for key: %?", k),
+        }
+    }
+
     /// Return true if the map contains a value for the specified key,
     /// using equivalence
     pub fn contains_key_equiv<Q:Hash + Equiv<K>>(&self, key: &Q) -> bool {