pub struct OptionCache<K: PartialEq, V> { /* private fields */ }Expand description
A simple cache mapping keys to optional computed values.
If a key is present and Some, the cached value is returned.
If a key is absent, the computation is run and cached.
Implementations§
Source§impl<K: PartialEq, V: Clone> OptionCache<K, V>
impl<K: PartialEq, V: Clone> OptionCache<K, V>
Sourcepub fn get_or_insert_with(
&mut self,
key: K,
compute: impl FnOnce() -> Option<V>,
) -> Option<V>where
K: Clone,
pub fn get_or_insert_with(
&mut self,
key: K,
compute: impl FnOnce() -> Option<V>,
) -> Option<V>where
K: Clone,
Get or compute a value for key.
If the key is already cached, returns the cached value.
Otherwise runs compute and caches the result.
Sourcepub fn invalidate(&mut self, key: &K)
pub fn invalidate(&mut self, key: &K)
Invalidate (remove) an entry.
Trait Implementations§
Source§impl<K: Clone + PartialEq, V: Clone> Clone for OptionCache<K, V>
impl<K: Clone + PartialEq, V: Clone> Clone for OptionCache<K, V>
Source§fn clone(&self) -> OptionCache<K, V>
fn clone(&self) -> OptionCache<K, V>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<K, V> Freeze for OptionCache<K, V>
impl<K, V> RefUnwindSafe for OptionCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for OptionCache<K, V>
impl<K, V> Sync for OptionCache<K, V>
impl<K, V> Unpin for OptionCache<K, V>
impl<K, V> UnsafeUnpin for OptionCache<K, V>
impl<K, V> UnwindSafe for OptionCache<K, V>where
K: UnwindSafe,
V: UnwindSafe,
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