pub struct Cached<T: 'static> { /* private fields */ }Expand description
RAII guard that borrows a value from a thread-local cache and returns it on drop.
Guards are thread-affine and must be dropped on the same thread where they were created.
Implementations§
Source§impl<T: 'static> Cached<T>
impl<T: 'static> Cached<T>
Sourcepub fn take<E>(
cache: &'static LocalKey<RefCell<(bool, Option<T>)>>,
create: impl FnOnce() -> Result<T, E>,
reset: impl FnOnce(&mut T) -> Result<(), E>,
) -> Result<Self, E>
pub fn take<E>( cache: &'static LocalKey<RefCell<(bool, Option<T>)>>, create: impl FnOnce() -> Result<T, E>, reset: impl FnOnce(&mut T) -> Result<(), E>, ) -> Result<Self, E>
Take a value from the thread-local cache.
On a cache hit the reset closure reconfigures the existing instance.
On a miss the create closure constructs a new one. Both closures may
fail with E.
This cache provides no synchronization guarantees. Attempting to take a second guard from the same cache on the same thread while one is already held will panic.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Cached<T>where
T: Freeze,
impl<T> RefUnwindSafe for Cached<T>where
T: RefUnwindSafe,
impl<T> !Send for Cached<T>
impl<T> !Sync for Cached<T>
impl<T> Unpin for Cached<T>where
T: Unpin,
impl<T> UnsafeUnpin for Cached<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Cached<T>where
T: 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