pub struct LruCache<K, V> { /* private fields */ }Expand description
A generic fixed-capacity LRU (Least Recently Used) cache.
The cache stores up to capacity key-value pairs. When full, the
least recently accessed entry is evicted to make room for new ones.
Implementations§
Source§impl<K: Clone + Eq + Hash, V> LruCache<K, V>
impl<K: Clone + Eq + Hash, V> LruCache<K, V>
Sourcepub fn get(&mut self, key: &K) -> Option<&V>
pub fn get(&mut self, key: &K) -> Option<&V>
Look up a key, returning a reference to the value if present.
This promotes the entry to the most recently used position.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<(K, V)>
pub fn insert(&mut self, key: K, value: V) -> Option<(K, V)>
Insert a key-value pair. If the key already exists, update the value. Returns the evicted key-value pair if the cache was full.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Remove a key from the cache, returning its value if present.
Sourcepub fn stats(&self) -> &CacheStats
pub fn stats(&self) -> &CacheStats
Return a reference to the cache statistics.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for LruCache<K, V>
impl<K, V> RefUnwindSafe for LruCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for LruCache<K, V>
impl<K, V> Sync for LruCache<K, V>
impl<K, V> Unpin for LruCache<K, V>
impl<K, V> UnsafeUnpin for LruCache<K, V>
impl<K, V> UnwindSafe for LruCache<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more