pub struct LruMap<K: PartialEq, V, const S: usize> { /* private fields */ }Expand description
The LruMap (i.e. Least Recently Used Map) is a map of keys to values, with a fixed capacity. Adding keys beyond the capacity will remove the least recently accessed key-value tuple and return it.
Implementations§
Source§impl<K: PartialEq, V, const S: usize> LruMap<K, V, S>
impl<K: PartialEq, V, const S: usize> LruMap<K, V, S>
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 new entry to the cache, and evict the least recently used one if capacity has been reached
Sourcepub fn get(&mut self, key: &K) -> Option<&V>
pub fn get(&mut self, key: &K) -> Option<&V>
Get the value by key if it exists
If you need a mutable reference, you can use “as_mut”
Sourcepub fn get_least_recently_used(&mut self) -> Option<(&mut K, &mut V)>
pub fn get_least_recently_used(&mut self) -> Option<(&mut K, &mut V)>
Returns None if there is still more capacity, or if there is no LRU.
Auto Trait Implementations§
impl<K, V, const S: usize> Freeze for LruMap<K, V, S>
impl<K, V, const S: usize> RefUnwindSafe for LruMap<K, V, S>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, const S: usize> Send for LruMap<K, V, S>
impl<K, V, const S: usize> Sync for LruMap<K, V, S>
impl<K, V, const S: usize> Unpin for LruMap<K, V, S>
impl<K, V, const S: usize> UnwindSafe for LruMap<K, V, S>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