Struct scc::hash_cache::OccupiedEntry

source ·
pub struct OccupiedEntry<'h, K, V, H = RandomState>
where H: BuildHasher,
{ /* private fields */ }
Expand description

OccupiedEntry is a view into an occupied cache entry in a HashCache.

Implementations§

source§

impl<'h, K, V, H> OccupiedEntry<'h, K, V, H>
where K: Eq + Hash, H: BuildHasher,

source

pub fn key(&self) -> &K

Gets a reference to the key in the entry.

§Examples
use scc::HashCache;

let hashcache: HashCache<u64, u32> = HashCache::default();

assert_eq!(hashcache.entry(29).or_default().1.key(), &29);
source

pub fn remove_entry(self) -> (K, V)

Takes ownership of the key and value from the HashCache.

§Examples
use scc::HashCache;
use scc::hash_cache::Entry;

let hashcache: HashCache<u64, u32> = HashCache::default();

hashcache.entry(11).or_put(17);

if let Entry::Occupied(o) = hashcache.entry(11) {
    assert_eq!(o.remove_entry(), (11, 17));
};
source

pub fn get(&self) -> &V

Gets a reference to the value in the entry.

§Examples
use scc::HashCache;
use scc::hash_cache::Entry;

let hashcache: HashCache<u64, u32> = HashCache::default();

hashcache.entry(19).or_put(11);

if let Entry::Occupied(o) = hashcache.entry(19) {
    assert_eq!(o.get(), &11);
};
source

pub fn get_mut(&mut self) -> &mut V

Gets a mutable reference to the value in the entry.

§Examples
use scc::HashCache;
use scc::hash_cache::Entry;

let hashcache: HashCache<u64, u32> = HashCache::default();

hashcache.entry(37).or_put(11);

if let Entry::Occupied(mut o) = hashcache.entry(37) {
    *o.get_mut() += 18;
    assert_eq!(*o.get(), 29);
}

assert_eq!(*hashcache.get(&37).unwrap().get(), 29);
source

pub fn put(&mut self, val: V) -> V

Sets the value of the entry, and returns the old value.

§Examples
use scc::HashCache;
use scc::hash_cache::Entry;

let hashcache: HashCache<u64, u32> = HashCache::default();

hashcache.entry(37).or_put(11);

if let Entry::Occupied(mut o) = hashcache.entry(37) {
    assert_eq!(o.put(17), 11);
}

assert_eq!(*hashcache.get(&37).unwrap().get(), 17);
source

pub fn remove(self) -> V

Takes the value out of the entry, and returns it.

§Examples
use scc::HashCache;
use scc::hash_cache::Entry;

let hashcache: HashCache<u64, u32> = HashCache::default();

hashcache.entry(11).or_put(17);

if let Entry::Occupied(o) = hashcache.entry(11) {
    assert_eq!(o.remove(), 17);
};

Trait Implementations§

source§

impl<'h, K, V, H> Debug for OccupiedEntry<'h, K, V, H>
where K: Debug + Eq + Hash, V: Debug, H: BuildHasher,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'h, K, V, H> Freeze for OccupiedEntry<'h, K, V, H>

§

impl<'h, K, V, H = RandomState> !RefUnwindSafe for OccupiedEntry<'h, K, V, H>

§

impl<'h, K, V, H> Send for OccupiedEntry<'h, K, V, H>
where K: Eq + Hash + Send + Sync, V: Send + Sync, H: Sync,

§

impl<'h, K, V, H> Sync for OccupiedEntry<'h, K, V, H>
where H: Sync, K: Sync, V: Sync,

§

impl<'h, K, V, H> Unpin for OccupiedEntry<'h, K, V, H>

§

impl<'h, K, V, H = RandomState> !UnwindSafe for OccupiedEntry<'h, K, V, H>

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.