diff --git a/src/map.rs b/src/map.rs index b346b77d..9ae9beaa 100644 --- a/src/map.rs +++ b/src/map.rs @@ -693,6 +693,10 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { pub fn get_mut(&mut self) -> &mut V { &mut self.map.entries[self.index].value } + pub fn get_entry_mut(&mut self) -> (&K, &mut V) { + let bucket = &mut self.map.entries[self.index]; + (&bucket.key, &mut bucket.value) + } /// Put the new key in the occupied entry's key slot pub(crate) fn replace_key(self) -> K { @@ -707,6 +711,10 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { pub fn into_mut(self) -> &'a mut V { &mut self.map.entries[self.index].value } + pub fn into_entry_mut(self) -> (&'a K, &'a mut V) { + let bucket = &mut self.map.entries[self.index]; + (&bucket.key, &mut bucket.value) + } /// Sets the value of the entry to `value`, and returns the entry's old value. pub fn insert(&mut self, value: V) -> V { @@ -811,6 +819,14 @@ impl<'a, K, V> VacantEntry<'a, K, V> { } } + pub fn insert_entry(self, value: V) -> (&'a K, &'a mut V) { + if self.map.size_class_is_64bit() { + self.insert_entry_impl::(value) + } else { + self.insert_entry_impl::(value) + } + } + fn insert_impl(self, value: V) -> &'a mut V where Sz: Size, @@ -825,6 +841,22 @@ impl<'a, K, V> VacantEntry<'a, K, V> { self.map.insert_phase_2::(self.probe, old_pos); &mut { self.map }.entries[index].value } + + fn insert_entry_impl(self, value: V) -> (&'a K, &'a mut V) + where + Sz: Size, + { + let index = self.map.entries.len(); + self.map.entries.push(Bucket { + hash: self.hash, + key: self.key, + value, + }); + let old_pos = Pos::with_hash::(index, self.hash); + self.map.insert_phase_2::(self.probe, old_pos); + let entry = &mut { self.map }.entries[index]; + (&entry.key, &mut entry.value) + } } impl<'a, K: 'a + fmt::Debug, V: 'a> fmt::Debug for VacantEntry<'a, K, V> {