Skip to main content

AnyLruCache

Trait AnyLruCache 

Source
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§

Source

fn len(&self) -> usize

Returns the number of key-value pairs that are currently on this backend.

Source

fn cap(&self) -> NonZeroUsize

Returns the logical maximum capacity of this cache backend.

Source

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.

Source

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.

Source

fn get<Q>(&mut self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Returns a reference to the value corresponding to the key, moving it to the MRU position.

Source

fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Returns a mutable reference to the value corresponding to the key, moving it to the MRU position.

Source

fn peek<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Returns a reference to the value corresponding to the key without updating the LRU state.

Source

fn clear(&mut self)

Clears the cache, removing all values.

Source

fn pop_lru(&mut self) -> Option<(K, V)>

Removes and returns the explicitly Least Recently Used key-value pair.

Source

fn contains<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Checks if the cache contains the given key.

Source

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.

Source

fn pop<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Removes the given key from the cache and returns its associated value.

Source

fn pop_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Removes the given key from the cache and returns the (key, value) pair.

Source

fn promote<Q>(&mut self, key: &Q)
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Explicitly marks the given key as the Most Recently Used.

Source

fn demote<Q>(&mut self, key: &Q)
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Explicitly marks the given key as the Least Recently Used.

Source

fn peek_lru(&self) -> Option<(&K, &V)>

Returns a reference to the Least Recently Used pair without removing it.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the cache is empty.

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.

Implementations on Foreign Types§

Source§

impl<K: Hash + Eq + Ord, V> AnyLruCache<K, V> for LruCache<K, V>

Source§

fn len(&self) -> usize

Source§

fn cap(&self) -> NonZeroUsize

Source§

fn put(&mut self, key: K, value: V) -> Option<V>

Source§

fn put_with_cap( &mut self, key: K, value: V, _cap: NonZeroUsize, ) -> (Option<V>, Result<(), (K, V)>)

Source§

fn get<Q>(&mut self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Source§

fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Source§

fn peek<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Source§

fn clear(&mut self)

Source§

fn pop_lru(&mut self) -> Option<(K, V)>

Source§

fn contains<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Source§

fn push(&mut self, key: K, value: V) -> Option<(K, V)>

Source§

fn pop<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Source§

fn pop_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Source§

fn promote<Q>(&mut self, key: &Q)
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Source§

fn demote<Q>(&mut self, key: &Q)
where K: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Source§

fn peek_lru(&self) -> Option<(&K, &V)>

Implementors§

Source§

impl<K, V, const N: usize, I, S> AnyLruCache<K, V> for SmallLruCache<K, V, N, I, S>
where K: Hash + Eq + Ord + Clone, I: IndexType, S: AnyLruCache<K, V>,

Source§

impl<K, V, const N: usize, I: IndexType> AnyLruCache<K, V> for HeaplessBTreeLruCache<K, V, N, I>
where K: Hash + Eq + Ord + Clone,

Source§

impl<K, V, const N: usize, I: IndexType> AnyLruCache<K, V> for HeaplessLinearLruCache<K, V, N, I>
where K: Hash + Eq + Ord + Clone,

Source§

impl<K, V, const N: usize, I: IndexType> AnyLruCache<K, V> for HeaplessLruCache<K, V, N, I>
where K: Hash + Eq + Ord + Clone,