[−][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 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]
I: Eq + Hash,
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.
impl<'a, I, O, S> HashCache<'a, I, O, S> where
I: Eq + Hash,
S: BuildHasher,
[src]
I: Eq + Hash,
S: BuildHasher,
pub fn with_hasher<F>(hash_builder: S, f: F) -> Self where
F: Fn(&mut Self, &I) -> O + 'a,
[src]
F: Fn(&mut Self, &I) -> O + 'a,
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]
I: Eq + Hash,
S: BuildHasher,
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,
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]
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> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,