about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-06-15 07:37:27 -0700
committerGitHub <noreply@github.com>2016-06-15 07:37:27 -0700
commit9b06d2ad335fb53917d79f4e20b03d98ab179bc2 (patch)
treeb13951db200c5fffdcad393d798789369f3cbdd1 /src/libstd
parenta94881563c18e4ffca2e24aed4bd8f5de583cc91 (diff)
parent217a964027bebd7c1ed95b2e242e69bc810b821a (diff)
downloadrust-9b06d2ad335fb53917d79f4e20b03d98ab179bc2.tar.gz
rust-9b06d2ad335fb53917d79f4e20b03d98ab179bc2.zip
Auto merge of #33300 - seanmonstar:map-entry-take, r=alexcrichton
Map::Entry methods to recover key and value together

See https://github.com/rust-lang/rust/issues/32281#issuecomment-213066344
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/collections/hash/map.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index 37045822d47..536f168e401 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -1552,6 +1552,12 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
         self.elem.read().0
     }
 
+    /// Take the ownership of the key and value from the map.
+    #[unstable(feature = "map_entry_recover_keys", issue = "34285")]
+    pub fn remove_pair(self) -> (K, V) {
+        pop_internal(self.elem)
+    }
+
     /// Gets a reference to the value in the entry.
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn get(&self) -> &V {
@@ -1584,6 +1590,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
     pub fn remove(self) -> V {
         pop_internal(self.elem).1
     }
+
     /// Returns a key that was used for search.
     ///
     /// The key was retained for further use.
@@ -1600,6 +1607,12 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
         &self.key
     }
 
+    /// Take ownership of the key.
+    #[unstable(feature = "map_entry_recover_keys", issue = "34285")]
+    pub fn into_key(self) -> K {
+        self.key
+    }
+
     /// Sets the value of the entry with the VacantEntry's key,
     /// and returns a mutable reference to it
     #[stable(feature = "rust1", since = "1.0.0")]