pub struct ThunkCache { /* private fields */ }Expand description
A named cache of lazy values.
Useful for memoizing top-level definitions that should only be evaluated once during a program run.
Implementations§
Source§impl ThunkCache
impl ThunkCache
Sourcepub fn insert<T, F>(&mut self, name: impl Into<String>, f: F)
pub fn insert<T, F>(&mut self, name: impl Into<String>, f: F)
Insert a lazily-computed entry under name.
If name is already in the cache the old entry is replaced.
Sourcepub fn insert_pure<T>(&mut self, name: impl Into<String>, value: T)
pub fn insert_pure<T>(&mut self, name: impl Into<String>, value: T)
Insert a pre-evaluated value under name.
Sourcepub fn force<T>(&self, name: &str) -> Option<T>
pub fn force<T>(&self, name: &str) -> Option<T>
Force and return the value under name, if it exists.
Trait Implementations§
Source§impl Debug for ThunkCache
impl Debug for ThunkCache
Auto Trait Implementations§
impl Freeze for ThunkCache
impl !RefUnwindSafe for ThunkCache
impl Send for ThunkCache
impl Sync for ThunkCache
impl Unpin for ThunkCache
impl UnsafeUnpin for ThunkCache
impl !UnwindSafe for ThunkCache
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