pub struct CachedFunction<TFunction, TInput, TReturn>{ /* private fields */ }
Expand description
Wraps an immutable function such that the results of its invocation
are cached to a HashMap<TInput, TReturn>
.
Implementations§
Source§impl<TFunction, TInput, TReturn> CachedFunction<TFunction, TInput, TReturn>
impl<TFunction, TInput, TReturn> CachedFunction<TFunction, TInput, TReturn>
Sourcepub fn new(function: TFunction) -> CachedFunction<TFunction, TInput, TReturn>
pub fn new(function: TFunction) -> CachedFunction<TFunction, TInput, TReturn>
Returns a CachedFunction<TFunction, TInput, TReturn>
that wraps the input function.
§Arguments
function
- The function to wrap in a cache.
§Examples
use std::thread;
use std::time::Duration;
use function_cache::CachedFunction;
let mut cached_function = CachedFunction::new(|x: i32| {
thread::sleep(Duration::from_secs(2));
x
});
Auto Trait Implementations§
impl<TFunction, TInput, TReturn> Freeze for CachedFunction<TFunction, TInput, TReturn>where
TFunction: Freeze,
impl<TFunction, TInput, TReturn> RefUnwindSafe for CachedFunction<TFunction, TInput, TReturn>
impl<TFunction, TInput, TReturn> Send for CachedFunction<TFunction, TInput, TReturn>
impl<TFunction, TInput, TReturn> Sync for CachedFunction<TFunction, TInput, TReturn>
impl<TFunction, TInput, TReturn> Unpin for CachedFunction<TFunction, TInput, TReturn>
impl<TFunction, TInput, TReturn> UnwindSafe for CachedFunction<TFunction, TInput, TReturn>
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