Trait fn_cache::FnCache

source ·
pub trait FnCache<I, O> {
    // Required method
    fn get(&mut self, input: I) -> &O;
}
Expand description

The generic trait for all caches.

This trait is implemented on all caches. This allows someone to write a function like fn f(cache: &mut impl FnCache<u32,u32>, x: &u32) -> u32 and have it work for all the caches written in this crate.

Required Methods§

source

fn get(&mut self, input: I) -> &O

Retrieve a value stored in the cache. If the value does not yet exist in the cache, the function is called, and the result is added to the cache before returning it.

Implementors§

source§

impl<'f, I, O> FnCache<I, O> for BTreeCache<'f, I, O>where I: Ord,

source§

impl<'f, I, O, S> FnCache<I, O> for HashCache<'f, I, O, S>where I: Eq + Hash, S: BuildHasher,

source§

impl<'f, O> FnCache<usize, O> for VecCache<'f, O>