[][src]Struct fn_cache::HashCache

pub struct HashCache<'a, I, O, S = RandomState> where
    I: Eq + Hash
{ /* fields omitted */ }

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 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> HashCache<'a, I, O, RandomState> where
    I: Eq + Hash
[src]

pub fn new<F>(f: F) -> Self where
    F: Fn(&mut Self, &I) -> 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.

impl<'a, I, O, S> HashCache<'a, I, O, S> where
    I: Eq + Hash,
    S: BuildHasher
[src]

pub fn with_hasher<F>(hash_builder: S, f: F) -> Self where
    F: Fn(&mut Self, &I) -> O + 'a, 
[src]

Create a HashCache which will use the given hash builder to hash keys.

See the documentation on HashMap for more details.

pub fn clear(&mut self)[src]

Clears the cache, removing all key-value pairs. Keeps the allocated memory for reuse.

pub fn len(&self) -> usize[src]

Returns the number of elements in the cache.

pub fn reserve(&mut self, additional: usize)[src]

Reserves capacity for at least additional more elements to be inserted in the cache. The collection may reserve more space to avoid frequent reallocations.

pub fn remove(&mut self, input: &I) -> Option<O>[src]

Removes the input from the cache, returning any value if the input was previously in the cache.

Trait Implementations

impl<'a, I, O, S> FnCache<I, O> for HashCache<'a, I, O, S> where
    I: Eq + Hash,
    S: BuildHasher
[src]

Auto Trait Implementations

impl<'a, I, O, S = RandomState> !Send for HashCache<'a, I, O, S>

impl<'a, I, O, S> Unpin for HashCache<'a, I, O, S> where
    I: Unpin,
    O: Unpin,
    S: Unpin

impl<'a, I, O, S = RandomState> !Sync for HashCache<'a, I, O, S>

impl<'a, I, O, S = RandomState> !UnwindSafe for HashCache<'a, I, O, S>

impl<'a, I, O, S = RandomState> !RefUnwindSafe for HashCache<'a, I, O, S>

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> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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