[−][src]Struct fn_cache::VecCache
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]
O: Into<V>,
pub fn new<F>(f: F) -> Self where
F: Fn(&mut Self, usize) -> O + 'a, [src]
F: Fn(&mut Self, usize) -> O + 'a,
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,
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]
U: From<T>,
impl<T> From<T> for T[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,