Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K, V, S, A> {
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> {
Expand Down Expand Up @@ -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<K, V, S, A> {
self.table
}
}

impl<'a, K, V, S, A: Allocator> VacantEntry<'a, K, V, S, A> {
Expand Down Expand Up @@ -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<K, V, S, A> {
self.table
}
}

impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator> EntryRef<'a, 'b, K, Q, V, S, A> {
Expand Down Expand Up @@ -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<K, V, S, A> {
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> {
Expand Down Expand Up @@ -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<K, V, S, A> {
self.table
}
}

impl<K, V, S, A> FromIterator<(K, V)> for HashMap<K, V, S, A>
Expand Down
8 changes: 8 additions & 0 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, A> {
match self {
Entry::Occupied(entry) => entry.table,
Entry::Vacant(entry) => entry.table,
}
}
}

/// A view into an occupied entry in a `HashTable`.
Expand Down