pub struct TwoLevelCache<K1, K2, Out>(RefCell<HashMap<K1, (bool, HashMap<K2, Pin<Box<Out>>>)>>);
Expand description
Pretty much copies the cache from rustc_utils, but adds a second layer so we can chech for recursion on only part of the key
Tuple Fields§
§0: RefCell<HashMap<K1, (bool, HashMap<K2, Pin<Box<Out>>>)>>
Implementations§
Source§impl<K1: Eq + Hash + Clone, K2: Eq + Hash + Clone, Out> TwoLevelCache<K1, K2, Out>
impl<K1: Eq + Hash + Clone, K2: Eq + Hash + Clone, Out> TwoLevelCache<K1, K2, Out>
Sourcepub fn get(&self, key: (K1, K2), compute: impl FnOnce((K1, K2)) -> Out) -> &Out
pub fn get(&self, key: (K1, K2), compute: impl FnOnce((K1, K2)) -> 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(
&self,
key: (K1, K2),
compute: impl FnOnce((K1, K2)) -> Out,
) -> Option<&Out>
pub fn get_maybe_recursive( &self, key: (K1, K2), compute: impl FnOnce((K1, K2)) -> Out, ) -> Option<&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: (K1, K2),
compute: impl FnOnce((K1, K2)) -> Option<Out>,
) -> Retrieval<&'a Out>
pub fn try_retrieve<'a>( &'a self, key: (K1, K2), compute: impl FnOnce((K1, K2)) -> 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: &(K1, K2)) -> bool
Trait Implementations§
Auto Trait Implementations§
impl<K1, K2, Out> !Freeze for TwoLevelCache<K1, K2, Out>
impl<K1, K2, Out> !RefUnwindSafe for TwoLevelCache<K1, K2, Out>
impl<K1, K2, Out> Send for TwoLevelCache<K1, K2, Out>
impl<K1, K2, Out> !Sync for TwoLevelCache<K1, K2, Out>
impl<K1, K2, Out> Unpin for TwoLevelCache<K1, K2, Out>
impl<K1, K2, Out> UnwindSafe for TwoLevelCache<K1, K2, Out>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more