Map::Entry::take() method to recover key and value together

This commit is contained in:
Sean McArthur 2016-06-14 05:22:41 -07:00
parent 1af8f3e362
commit 217a964027
2 changed files with 25 additions and 0 deletions

View File

@ -1898,6 +1898,12 @@ impl<'a, K: Ord, V> 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")]
@ -1950,6 +1956,12 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
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 {

View File

@ -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")]