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
});

Gets the value of evaluating the function with the arg as input. First, the cache is checked and if the value with arg has already be computed, it will be returned from the cache.

Arguments

  • arg - The argument to the function call.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.