pub trait Cache<K: Hash + Eq, V> {
fn put(&mut self, k: K, v: V) -> PutResult<K, V>;
fn get<'a, Q>(&mut self, k: &'a Q) -> Option<&'a V>
where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized;
fn get_mut<'a, Q>(&mut self, k: &'a Q) -> Option<&'a mut V>
where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized;
fn peek<'a, Q>(&self, k: &'a Q) -> Option<&'a V>
where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized;
fn peek_mut<'a, Q>(&mut self, k: &'a Q) -> Option<&'a mut V>
where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized;
fn contains<Q>(&self, k: &Q) -> bool
where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized;
fn remove<Q>(&mut self, k: &Q) -> Option<V>
where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized;
fn purge(&mut self);
fn len(&self) -> usize;
fn cap(&self) -> usize;
fn is_empty(&self) -> bool;
}Expand description
Cache contains the basic APIs for a cache. All of caches in this crate implement this trait.
Required Methods
sourcefn put(&mut self, k: K, v: V) -> PutResult<K, V>
fn put(&mut self, k: K, v: V) -> PutResult<K, V>
Puts a key-value pair into cache, returns a PutResult.
sourcefn get<'a, Q>(&mut self, k: &'a Q) -> Option<&'a V>where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
fn get<'a, Q>(&mut self, k: &'a Q) -> Option<&'a V>where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
Returns a reference to the value of the key in the cache or None if it
is not present in the cache. Update the cache if it exists.
sourcefn get_mut<'a, Q>(&mut self, k: &'a Q) -> Option<&'a mut V>where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
fn get_mut<'a, Q>(&mut self, k: &'a Q) -> Option<&'a mut V>where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
Returns a mutable reference to the value of the key in the cache or None if it
is not present in the cache. Update the cache if it exists.
sourcefn peek<'a, Q>(&self, k: &'a Q) -> Option<&'a V>where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
fn peek<'a, Q>(&self, k: &'a Q) -> Option<&'a V>where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
Returns a reference to the value corresponding to the key in the cache or None if it is
not present in the cache. Unlike get, peek does not update the cache so the key’s
position will be unchanged.
sourcefn peek_mut<'a, Q>(&mut self, k: &'a Q) -> Option<&'a mut V>where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
fn peek_mut<'a, Q>(&mut self, k: &'a Q) -> Option<&'a mut V>where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
Returns a mutable reference to the value corresponding to the key in the cache or None if it is
not present in the cache. Unlike get_mut, peek_mut does not update the cache so the key’s
position will be unchanged.
sourcefn contains<Q>(&self, k: &Q) -> boolwhere
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
fn contains<Q>(&self, k: &Q) -> boolwhere
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
Returns a bool indicating whether the given key is in the cache. Does not update the cache.
sourcefn remove<Q>(&mut self, k: &Q) -> Option<V>where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
fn remove<Q>(&mut self, k: &Q) -> Option<V>where
KeyRef<K>: Borrow<Q>,
Q: Eq + Hash + ?Sized,
Removes and returns the value corresponding to the key from the cache or
None if it does not exist.