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>
impl<'h, K, V, H> OccupiedEntry<'h, K, V, H>
sourcepub fn key(&self) -> &K
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);
sourcepub fn remove_entry(self) -> (K, V)
pub fn remove_entry(self) -> (K, V)
sourcepub fn get(&self) -> &V
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);
};
sourcepub fn get_mut(&mut self) -> &mut V
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);
sourcepub fn put(&mut self, val: V) -> V
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);
sourcepub fn remove(self) -> V
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>
impl<'h, K, V, H> Debug for OccupiedEntry<'h, K, V, H>
source§impl<'h, K, V, H> Deref for OccupiedEntry<'h, K, V, H>
impl<'h, K, V, H> Deref for OccupiedEntry<'h, K, V, H>
Auto Trait Implementations§
impl<'h, K, V, H> Freeze for OccupiedEntry<'h, K, V, H>
impl<'h, K, V, H> RefUnwindSafe for OccupiedEntry<'h, K, V, H>
impl<'h, K, V, H> Send for OccupiedEntry<'h, K, V, H>
impl<'h, K, V, H> Sync for OccupiedEntry<'h, K, V, H>
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> 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