pub trait AnyLruCache<K, V> {
Show 17 methods
// Required methods
fn len(&self) -> usize;
fn cap(&self) -> NonZeroUsize;
fn put(&mut self, key: K, value: V) -> Option<V>;
fn put_with_cap(
&mut self,
key: K,
value: V,
cap: NonZeroUsize,
) -> (Option<V>, Result<(), (K, V)>);
fn get<Q>(&mut self, key: &Q) -> Option<&V>
where K: Borrow<Q>,
Q: Hash + Eq + Ord + ?Sized;
fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>,
Q: Hash + Eq + Ord + ?Sized;
fn peek<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>,
Q: Hash + Eq + Ord + ?Sized;
fn clear(&mut self);
fn pop_lru(&mut self) -> Option<(K, V)>;
fn contains<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>,
Q: Hash + Eq + Ord + ?Sized;
fn push(&mut self, key: K, value: V) -> Option<(K, V)>;
fn pop<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>,
Q: Hash + Eq + Ord + ?Sized;
fn pop_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>,
Q: Hash + Eq + Ord + ?Sized;
fn promote<Q>(&mut self, key: &Q)
where K: Borrow<Q>,
Q: Hash + Eq + Ord + ?Sized;
fn demote<Q>(&mut self, key: &Q)
where K: Borrow<Q>,
Q: Hash + Eq + Ord + ?Sized;
fn peek_lru(&self) -> Option<(&K, &V)>;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
An object-safe abstraction over LRU cache types.
Required Methods§
Sourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the number of key-value pairs that are currently on this backend.
Sourcefn cap(&self) -> NonZeroUsize
fn cap(&self) -> NonZeroUsize
Returns the logical maximum capacity of this cache backend.
Sourcefn put(&mut self, key: K, value: V) -> Option<V>
fn put(&mut self, key: K, value: V) -> Option<V>
Inserts a key-value pair, updating the value if the key already exists. Returns the old value if the key was present.
Sourcefn put_with_cap(
&mut self,
key: K,
value: V,
cap: NonZeroUsize,
) -> (Option<V>, Result<(), (K, V)>)
fn put_with_cap( &mut self, key: K, value: V, cap: NonZeroUsize, ) -> (Option<V>, Result<(), (K, V)>)
Inserts a key-value pair with a specific maximum capacity enforcement.
Returns (old_value, Result<(), (key, value)>). The result is an error if capacity is reached and the backend cannot grow.
Sourcefn get<Q>(&mut self, key: &Q) -> Option<&V>
fn get<Q>(&mut self, key: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key, moving it to the MRU position.
Sourcefn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key, moving it to the MRU position.
Sourcefn peek<Q>(&self, key: &Q) -> Option<&V>
fn peek<Q>(&self, key: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key without updating the LRU state.
Sourcefn pop_lru(&mut self) -> Option<(K, V)>
fn pop_lru(&mut self) -> Option<(K, V)>
Removes and returns the explicitly Least Recently Used key-value pair.
Sourcefn push(&mut self, key: K, value: V) -> Option<(K, V)>
fn push(&mut self, key: K, value: V) -> Option<(K, V)>
Pushes a key-value pair into the cache. If the key already exists, updates the value. If pushing causes the capacity to be exceeded, returns the evicted LRU entry.
Sourcefn pop<Q>(&mut self, key: &Q) -> Option<V>
fn pop<Q>(&mut self, key: &Q) -> Option<V>
Removes the given key from the cache and returns its associated value.
Sourcefn pop_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
fn pop_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Removes the given key from the cache and returns the (key, value) pair.
Provided Methods§
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.