pub struct VacantEntry<'a, K, V, S = BuildHasherDefault<AHasher>, A = Global>where
A: Allocator,{ /* private fields */ }Expand description
A view into a vacant entry in a HashMap.
It is part of the Entry enum.
§Examples
use rune::alloc::hash_map::{Entry, HashMap, VacantEntry};
let mut map = HashMap::<&str, i32>::new();
let entry_v: VacantEntry<_, _, _> = match map.entry("a") {
Entry::Vacant(view) => view,
Entry::Occupied(_) => unreachable!(),
};
entry_v.try_insert(10)?;
assert!(map[&"a"] == 10 && map.len() == 1);
// Nonexistent key (insert and update)
match map.entry("b") {
Entry::Occupied(_) => unreachable!(),
Entry::Vacant(view) => {
let value = view.try_insert(2)?;
assert_eq!(*value, 2);
*value = 20;
}
}
assert!(map[&"b"] == 20 && map.len() == 2);Auto Trait Implementations§
impl<'a, K, V, S, A> Freeze for VacantEntry<'a, K, V, S, A>where
K: Freeze,
impl<'a, K, V, S, A> RefUnwindSafe for VacantEntry<'a, K, V, S, A>
impl<'a, K, V, S, A> Send for VacantEntry<'a, K, V, S, A>
impl<'a, K, V, S, A> Sync for VacantEntry<'a, K, V, S, A>
impl<'a, K, V, S, A> Unpin for VacantEntry<'a, K, V, S, A>where
K: Unpin,
impl<'a, K, V, S = BuildHasherDefault<AHasher>, A = Global> !UnwindSafe for VacantEntry<'a, K, V, S, A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more