pub trait Cache<K: Hash + Eq, V> {
// Required methods
fn put(&mut self, k: K, v: V) -> PutResult<K, V>;
fn get<Q>(&mut self, k: &Q) -> Option<&V>
where K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
fn peek<Q>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
fn peek_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
fn contains<Q>(&self, k: &Q) -> bool
where K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
fn remove<Q>(&mut self, k: &Q) -> Option<V>
where K: Borrow<Q>,
Q: Hash + Eq + ?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<Q>(&mut self, k: &Q) -> Option<&V>
fn get<Q>(&mut self, k: &Q) -> Option<&V>
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<Q>(&mut self, k: &Q) -> Option<&mut V>
fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
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<Q>(&self, k: &Q) -> Option<&V>
fn peek<Q>(&self, k: &Q) -> Option<&V>
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<Q>(&mut self, k: &Q) -> Option<&mut V>
fn peek_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
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) -> bool
fn contains<Q>(&self, k: &Q) -> bool
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>
fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes and returns the value corresponding to the key from the cache or
None if it does not exist.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.