Trait Cache

Source
pub trait Cache {
    type Arg;
    type Output;

    // Required methods
    fn new() -> Self;
    fn get(&self, arg: &Self::Arg) -> Option<&Self::Output>;
    fn cache(&mut self, arg: Self::Arg, result: Self::Output);
    fn clear(&mut self);
}
Expand description

The cache for single-thread memoization.

Required Associated Types§

Required Methods§

Source

fn new() -> Self

Create an empty cache.

Source

fn get(&self, arg: &Self::Arg) -> Option<&Self::Output>

Gets the cached result of arg. If it is not cached, returns None.

Source

fn cache(&mut self, arg: Self::Arg, result: Self::Output)

Caches the arg with result.

Source

fn clear(&mut self)

Clears the cache.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<Arg: Clone + Eq + Hash, Output: Clone> Cache for HashMap<Arg, Output>

Use HashMap as Cache.

Source§

type Arg = Arg

Source§

type Output = Output

Source§

fn new() -> Self

Source§

fn get(&self, arg: &Arg) -> Option<&Output>

Source§

fn cache(&mut self, arg: Arg, result: Output)

Source§

fn clear(&mut self)

Source§

impl<Output: Clone> Cache for Vec<Option<Output>>

Use Vec as Cache for sequences.

Source§

type Arg = usize

Source§

type Output = Output

Source§

fn new() -> Self

Source§

fn get(&self, arg: &usize) -> Option<&Output>

Source§

fn cache(&mut self, arg: usize, result: Output)

Source§

fn clear(&mut self)

Implementors§