[][src]Struct fn_cache::VecCache

pub struct VecCache<'a, O, V = O> where
    O: Into<V>, 
{ /* fields omitted */ }

A cache for a function which uses a Vec.

This cache is optimized for functions which must be calculated in order, so that there can be no gaps in the cache, and use usize as an argument.

If the function does not start at zero, or require every previous value to be calculated for the next one, consider using a HashCache instead.

The value in the cache V can be different than the output of the function O, as long as O implements Into<V>. If no conversion is required, than the V parameter can be elided.

Methods

impl<'a, O, V> VecCache<'a, O, V> where
    O: Into<V>, 
[src]

pub fn new<F>(f: F) -> Self where
    F: Fn(&mut Self, usize) -> O + 'a, 
[src]

Create a cache for the provided function. If the function stores references, the cache can only live as long as those references.

pub fn get(&mut self, input: usize) -> &V[src]

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.

Auto Trait Implementations

impl<'a, O, V> Unpin for VecCache<'a, O, V> where
    V: Unpin

impl<'a, O, V = O> !Sync for VecCache<'a, O, V>

impl<'a, O, V = O> !Send for VecCache<'a, O, V>

impl<'a, O, V = O> !UnwindSafe for VecCache<'a, O, V>

impl<'a, O, V = O> !RefUnwindSafe for VecCache<'a, O, V>

Blanket Implementations

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

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

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.

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.

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

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

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