Skip to main content

RawEntryMut

Enum RawEntryMut 

Source
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§

Source§

impl<'a, K: Debug, V: Debug> Debug for RawEntryMut<'a, K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, K, V> !UnwindSafe for RawEntryMut<'a, K, V>

§

impl<'a, K, V> Freeze for RawEntryMut<'a, K, V>
where RawOccupiedEntryMut<'a, K, V>: Freeze, RawVacantEntryMut<'a, K, V>: Freeze,

§

impl<'a, K, V> RefUnwindSafe for RawEntryMut<'a, K, V>

§

impl<'a, K, V> Send for RawEntryMut<'a, K, V>
where RawOccupiedEntryMut<'a, K, V>: Send, RawVacantEntryMut<'a, K, V>: Send,

§

impl<'a, K, V> Sync for RawEntryMut<'a, K, V>
where RawOccupiedEntryMut<'a, K, V>: Sync, RawVacantEntryMut<'a, K, V>: Sync,

§

impl<'a, K, V> Unpin for RawEntryMut<'a, K, V>
where RawOccupiedEntryMut<'a, K, V>: Unpin, RawVacantEntryMut<'a, K, V>: Unpin,

§

impl<'a, K, V> UnsafeUnpin for RawEntryMut<'a, K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.