Struct function_cache::CachedFunction [−][src]
pub struct CachedFunction<TFunction, TInput, TReturn> where
TFunction: Fn(TInput) -> TReturn,
TInput: Eq + Hash + Copy,
TReturn: Copy, { /* fields omitted */ }
Expand description
Wraps an immutable function such that the results of its invocation
are cached to a HashMap<TInput, TReturn>
.
Implementations
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> RefUnwindSafe for CachedFunction<TFunction, TInput, TReturn> where
TFunction: RefUnwindSafe,
TInput: RefUnwindSafe,
TReturn: RefUnwindSafe,
impl<TFunction, TInput, TReturn> Send for CachedFunction<TFunction, TInput, TReturn> where
TFunction: Send,
TInput: Send,
TReturn: Send,
impl<TFunction, TInput, TReturn> Sync for CachedFunction<TFunction, TInput, TReturn> where
TFunction: Sync,
TInput: Sync,
TReturn: Sync,
impl<TFunction, TInput, TReturn> Unpin for CachedFunction<TFunction, TInput, TReturn> where
TFunction: Unpin,
TInput: Unpin,
TReturn: Unpin,
impl<TFunction, TInput, TReturn> UnwindSafe for CachedFunction<TFunction, TInput, TReturn> where
TFunction: UnwindSafe,
TInput: UnwindSafe,
TReturn: UnwindSafe,