Struct closure_cacher::Cacher[][src]

pub struct Cacher<I, O, T> where
    T: Fn(I) -> O, 
{ /* fields omitted */ }

Cacher Struct that allows provision of a closure and memoizes its output

Examples

use closure_cacher::Cacher;
let mut cacher = Cacher::new(|x| x + 1);
assert_eq!(cacher.get(&1), &2);

Implementations

impl<I: Eq + Hash + Copy, O, T> Cacher<I, O, T> where
    T: Fn(I) -> O, 
[src]

pub fn new(calc: T) -> Cacher<I, O, T>[src]

Creates new Cacher instance

pub fn get(&mut self, n: &I) -> &O[src]

Get value by applying the cacher provided closure

Auto Trait Implementations

impl<I, O, T> RefUnwindSafe for Cacher<I, O, T> where
    I: RefUnwindSafe,
    O: RefUnwindSafe,
    T: RefUnwindSafe

impl<I, O, T> Send for Cacher<I, O, T> where
    I: Send,
    O: Send,
    T: Send

impl<I, O, T> Sync for Cacher<I, O, T> where
    I: Sync,
    O: Sync,
    T: Sync

impl<I, O, T> Unpin for Cacher<I, O, T> where
    I: Unpin,
    O: Unpin,
    T: Unpin

impl<I, O, T> UnwindSafe for Cacher<I, O, T> where
    I: UnwindSafe,
    O: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.