diff --git a/src/map.rs b/src/map.rs index 2154ec3e1..062c340c8 100644 --- a/src/map.rs +++ b/src/map.rs @@ -3712,6 +3712,14 @@ impl<'a, K, V, S, A: Allocator> Entry<'a, K, V, S, A> { Entry::Vacant(_) => self, } } + + /// Converts the `Entry` into a mutable reference to the underlying map. + pub fn into_map(self) -> &'a mut HashMap { + match self { + Entry::Occupied(entry) => entry.table, + Entry::Vacant(entry) => entry.table, + } + } } impl<'a, K, V: Default, S, A: Allocator> Entry<'a, K, V, S, A> { @@ -4136,6 +4144,11 @@ impl<'a, K, V, S, A: Allocator> OccupiedEntry<'a, K, V, S, A> { } } } + + /// Converts the `OccupiedEntry` into a mutable reference to the underlying map. + pub fn into_map(self) -> &'a mut HashMap { + self.table + } } impl<'a, K, V, S, A: Allocator> VacantEntry<'a, K, V, S, A> { @@ -4238,6 +4251,11 @@ impl<'a, K, V, S, A: Allocator> VacantEntry<'a, K, V, S, A> { table: self.table, } } + + /// Converts the `VacantEntry` into a mutable reference to the underlying map. + pub fn into_map(self) -> &'a mut HashMap { + self.table + } } impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator> EntryRef<'a, 'b, K, Q, V, S, A> { @@ -4424,6 +4442,14 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator> EntryRef<'a, 'b, K, Q, V, S, A> { EntryRef::Vacant(entry) => EntryRef::Vacant(entry), } } + + /// Converts the `EntryRef` into a mutable reference to the underlying map. + pub fn into_map(self) -> &'a mut HashMap { + match self { + EntryRef::Occupied(entry) => entry.table, + EntryRef::Vacant(entry) => entry.table, + } + } } impl<'a, 'b, K, Q: ?Sized, V: Default, S, A: Allocator> EntryRef<'a, 'b, K, Q, V, S, A> { @@ -4761,6 +4787,11 @@ impl<'map, 'key, K, Q: ?Sized, V, S, A: Allocator> VacantEntryRef<'map, 'key, K, table: self.table, } } + + /// Converts the `VacantEntryRef` into a mutable reference to the underlying map. + pub fn into_map(self) -> &'map mut HashMap { + self.table + } } impl FromIterator<(K, V)> for HashMap diff --git a/src/table.rs b/src/table.rs index 094350442..833eef4e5 100644 --- a/src/table.rs +++ b/src/table.rs @@ -1945,6 +1945,14 @@ where Entry::Vacant(entry) => Entry::Vacant(entry), } } + + /// Converts the `Entry` into a mutable reference to the underlying table. + pub fn into_table(self) -> &'a mut HashTable { + match self { + Entry::Occupied(entry) => entry.table, + Entry::Vacant(entry) => entry.table, + } + } } /// A view into an occupied entry in a `HashTable`.