[−][src]Struct fn_cache::HashCache
A cache for a function which uses a HashMap.
The cache takes ownership of all inputs, but only passes a reference to the function, allowing it to store the input in the cache without any copies or clones.
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.
The requirements for a HashMap must be met,
specifically the keys must implement Eq and
Hash, and the following propery must hold:
k1 == k2 -> hash(k1) == hash(k2)
Methods
impl<'a, I, O, V> HashCache<'a, I, O, V> where
I: Eq + Hash,
O: Into<V>, [src]
I: Eq + Hash,
O: Into<V>,
pub fn new<F>(f: F) -> Self where
F: Fn(&mut Self, &I) -> O + 'a, [src]
F: Fn(&mut Self, &I) -> 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: I) -> &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, I, O, V = O> !Send for HashCache<'a, I, O, V>
impl<'a, I, O, V> Unpin for HashCache<'a, I, O, V> where
I: Unpin,
V: Unpin,
I: Unpin,
V: Unpin,
impl<'a, I, O, V = O> !Sync for HashCache<'a, I, O, V>
impl<'a, I, O, V = O> !UnwindSafe for HashCache<'a, I, O, V>
impl<'a, I, O, V = O> !RefUnwindSafe for HashCache<'a, I, O, V>
Blanket Implementations
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
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,