]> git.lizzy.rs Git - rust.git/commitdiff
Map::Entry::take() method to recover key and value together
authorSean McArthur <sean.monstar@gmail.com>
Tue, 14 Jun 2016 12:22:41 +0000 (05:22 -0700)
committerSean McArthur <sean.monstar@gmail.com>
Wed, 15 Jun 2016 12:45:50 +0000 (05:45 -0700)
src/libcollections/btree/map.rs
src/libstd/collections/hash/map.rs

index 43226d233687af57d777154e4c80533d2b15b6de..3b775dc2865eea0b2cb9ba1ea83731592098c600 100644 (file)
@@ -1898,6 +1898,12 @@ pub fn key(&self) -> &K {
         &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")]
@@ -1950,6 +1956,12 @@ pub fn key(&self) -> &K {
         self.handle.reborrow().into_kv().0
     }
 
+    /// Take ownership of the key and value from the map.
+    #[unstable(feature = "map_entry_recover_keys", issue = "34285")]
+    pub fn remove_pair(self) -> (K, V) {
+        self.remove_kv()
+    }
+
     /// Gets a reference to the value in the entry.
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn get(&self) -> &V {
index 37045822d47ec01d6c3b2f28d5167e71b786b2e7..536f168e4010843216c6bc07044ae6a57c78e1e4 100644 (file)
@@ -1552,6 +1552,12 @@ pub fn key(&self) -> &K {
         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 @@ pub fn insert(&mut self, mut value: V) -> 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 @@ pub fn key(&self) -> &K {
         &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")]