Skip to content

Commit f96b6b9

Browse files
committed
Add Entry::insert backend for rust-lang/rust#64656
1 parent 31ec80e commit f96b6b9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/rustc_entry.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,32 @@ impl<'a, K, V> RustcVacantEntry<'a, K, V> {
546546
let bucket = self.table.insert_no_grow(self.hash, (self.key, value));
547547
unsafe { &mut bucket.as_mut().1 }
548548
}
549+
550+
/// Sets the value of the entry with the RustcVacantEntry's key,
551+
/// and returns a RustcOccupiedEntry.
552+
///
553+
/// # Examples
554+
///
555+
/// ```
556+
/// use hashbrown::HashMap;
557+
/// use hashbrown::hash_map::RustcEntry;
558+
///
559+
/// let mut map: HashMap<&str, u32> = HashMap::new();
560+
///
561+
/// if let RustcEntry::Vacant(v) = map.rustc_entry("poneyland") {
562+
/// let o = v.insert_entry(37);
563+
/// assert_eq!(o.get(), &37);
564+
/// }
565+
/// ```
566+
#[inline]
567+
pub fn insert_entry(self, value: V) -> RustcOccupiedEntry<'a, K, V> {
568+
let bucket = self.table.insert_no_grow(self.hash, (self.key, value));
569+
RustcOccupiedEntry {
570+
key: None,
571+
elem: bucket,
572+
table: self.table,
573+
}
574+
}
549575
}
550576

551577
impl<K, V> IterMut<'_, K, V> {

0 commit comments

Comments
 (0)