pub struct Cache<In, Out>(/* private fields */);
Expand description
Cache for non-copyable types.
Implementations§
Source§impl<In, Out> Cache<In, Out>
impl<In, Out> Cache<In, Out>
Sourcepub fn get(&self, key: &In, compute: impl FnOnce(In) -> Out) -> &Out
pub fn get(&self, key: &In, compute: impl FnOnce(In) -> Out) -> &Out
Returns the cached value for the given key, or runs compute
if
the value is not in cache.
§Panics
If this is a recursive invocation for this key.
Sourcepub fn get_maybe_recursive<'a>(
&'a self,
key: &In,
compute: impl FnOnce(In) -> Out,
) -> Option<&'a Out>
pub fn get_maybe_recursive<'a>( &'a self, key: &In, compute: impl FnOnce(In) -> Out, ) -> Option<&'a Out>
Returns the cached value for the given key, or runs compute
if
the value is not in cache.
Returns None
if this is a recursive invocation of get
for key key
.
Sourcepub fn try_retrieve<'a>(
&'a self,
key: &In,
compute: impl FnOnce(In) -> Option<Out>,
) -> Retrieval<&'a Out>
pub fn try_retrieve<'a>( &'a self, key: &In, compute: impl FnOnce(In) -> Option<Out>, ) -> Retrieval<&'a Out>
Try to retrieve a value from the cache with a potentially fallible or recursive computation.
pub fn is_in_cache(&self, key: &In) -> bool
Trait Implementations§
Auto Trait Implementations§
impl<In, Out> !Freeze for Cache<In, Out>
impl<In, Out> !RefUnwindSafe for Cache<In, Out>
impl<In, Out> Send for Cache<In, Out>
impl<In, Out> !Sync for Cache<In, Out>
impl<In, Out> Unpin for Cache<In, Out>where
In: Unpin,
impl<In, Out> UnwindSafe for Cache<In, Out>where
In: UnwindSafe,
Out: 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