pub struct OccupiedEntry<'a, K, V, S = BuildHasherDefault<AHasher>, A = Global>where
A: Allocator,{ /* private fields */ }Expand description
A view into an occupied entry in a HashMap.
It is part of the Entry enum.
§Examples
use rune::alloc::hash_map::{Entry, HashMap, OccupiedEntry};
use rune::alloc::prelude::*;
let mut map = HashMap::new();
map.try_extend([("a", 10), ("b", 20), ("c", 30)])?;
let _entry_o: OccupiedEntry<_, _, _> = map.entry("a").try_insert(100)?;
assert_eq!(map.len(), 3);
// Existing key (insert and update)
match map.entry("a") {
Entry::Vacant(_) => unreachable!(),
Entry::Occupied(mut view) => {
assert_eq!(view.get(), &100);
let v = view.get_mut();
*v *= 10;
assert_eq!(view.insert(1111), 1000);
}
}
assert_eq!(map[&"a"], 1111);
assert_eq!(map.len(), 3);
// Existing key (take)
match map.entry("c") {
Entry::Vacant(_) => unreachable!(),
Entry::Occupied(view) => {
assert_eq!(view.remove_entry(), ("c", 30));
}
}
assert_eq!(map.get(&"c"), None);
assert_eq!(map.len(), 2);Auto Trait Implementations§
impl<'a, K, V, S, A> Freeze for OccupiedEntry<'a, K, V, S, A>where
K: Freeze,
impl<'a, K, V, S, A> RefUnwindSafe for OccupiedEntry<'a, K, V, S, A>
impl<'a, K, V, S, A> Unpin for OccupiedEntry<'a, K, V, S, A>where
K: Unpin,
impl<'a, K, V, S = BuildHasherDefault<AHasher>, A = Global> !UnwindSafe for OccupiedEntry<'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