Skip to content

Commit 9b06d2a

Browse files
authored
Auto merge of #33300 - seanmonstar:map-entry-take, r=alexcrichton
Map::Entry methods to recover key and value together See #32281 (comment)
2 parents a948815 + 217a964 commit 9b06d2a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/libcollections/btree/map.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,12 @@ impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
18981898
&self.key
18991899
}
19001900

1901+
/// Take ownership of the key.
1902+
#[unstable(feature = "map_entry_recover_keys", issue = "34285")]
1903+
pub fn into_key(self) -> K {
1904+
self.key
1905+
}
1906+
19011907
/// Sets the value of the entry with the VacantEntry's key,
19021908
/// and returns a mutable reference to it.
19031909
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1950,6 +1956,12 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
19501956
self.handle.reborrow().into_kv().0
19511957
}
19521958

1959+
/// Take ownership of the key and value from the map.
1960+
#[unstable(feature = "map_entry_recover_keys", issue = "34285")]
1961+
pub fn remove_pair(self) -> (K, V) {
1962+
self.remove_kv()
1963+
}
1964+
19531965
/// Gets a reference to the value in the entry.
19541966
#[stable(feature = "rust1", since = "1.0.0")]
19551967
pub fn get(&self) -> &V {

src/libstd/collections/hash/map.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,12 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
15521552
self.elem.read().0
15531553
}
15541554

1555+
/// Take the ownership of the key and value from the map.
1556+
#[unstable(feature = "map_entry_recover_keys", issue = "34285")]
1557+
pub fn remove_pair(self) -> (K, V) {
1558+
pop_internal(self.elem)
1559+
}
1560+
15551561
/// Gets a reference to the value in the entry.
15561562
#[stable(feature = "rust1", since = "1.0.0")]
15571563
pub fn get(&self) -> &V {
@@ -1584,6 +1590,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
15841590
pub fn remove(self) -> V {
15851591
pop_internal(self.elem).1
15861592
}
1593+
15871594
/// Returns a key that was used for search.
15881595
///
15891596
/// The key was retained for further use.
@@ -1600,6 +1607,12 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
16001607
&self.key
16011608
}
16021609

1610+
/// Take ownership of the key.
1611+
#[unstable(feature = "map_entry_recover_keys", issue = "34285")]
1612+
pub fn into_key(self) -> K {
1613+
self.key
1614+
}
1615+
16031616
/// Sets the value of the entry with the VacantEntry's key,
16041617
/// and returns a mutable reference to it
16051618
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)