pub enum RawEntryMut<'a, K, V> {
Occupied(RawOccupiedEntryMut<'a, K, V>),
Vacant(RawVacantEntryMut<'a, K, V>),
}Expand description
Result of KevyMap::raw_entry_mut.
Mirrors hashbrown::hash_map::RawEntryMut: an Occupied arm grants
read / mutate / consume access to the existing entry; a Vacant arm
can be filled with insert(k, v). The defining property — and the
reason this API exists distinct from get_mut — is that
RawOccupiedEntryMut::remove consumes self, which releases the
outstanding borrow on the map and lets the caller perform the
deletion within the same borrow scope.
use kevy_map::{KevyMap, RawEntryMut};
let mut m: KevyMap<u64, u64> = KevyMap::new();
m.insert(1, 0); // 0 marks an expired value
// look up and drop the expired entry with one probe
if let RawEntryMut::Occupied(e) = m.raw_entry_mut(&1) {
if *e.get() == 0 {
e.remove();
}
}
assert!(m.is_empty());Variants§
Occupied(RawOccupiedEntryMut<'a, K, V>)
The key was present; gives read / mutate / consume access.
use kevy_map::{KevyMap, RawEntryMut};
let mut m: KevyMap<u64, u64> = KevyMap::new();
m.insert(7, 1);
let RawEntryMut::Occupied(mut e) = m.raw_entry_mut(&7) else { panic!() };
*e.get_mut() += 1;
assert_eq!(m.get(&7), Some(&2));Vacant(RawVacantEntryMut<'a, K, V>)
The key was absent; insert(k, v) writes a new entry.
use kevy_map::{KevyMap, RawEntryMut};
let mut m: KevyMap<u64, u64> = KevyMap::new();
let RawEntryMut::Vacant(e) = m.raw_entry_mut(&7) else { panic!() };
*e.insert(7, 1) += 1;
assert_eq!(m.get(&7), Some(&2));Trait Implementations§
Auto Trait Implementations§
impl<'a, K, V> !UnwindSafe for RawEntryMut<'a, K, V>
impl<'a, K, V> Freeze for RawEntryMut<'a, K, V>
impl<'a, K, V> RefUnwindSafe for RawEntryMut<'a, K, V>
impl<'a, K, V> Send for RawEntryMut<'a, K, V>
impl<'a, K, V> Sync for RawEntryMut<'a, K, V>
impl<'a, K, V> Unpin for RawEntryMut<'a, K, V>
impl<'a, K, V> UnsafeUnpin for RawEntryMut<'a, K, V>
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