Enum lru_mem::TryInsertError
source · pub enum TryInsertError<K, V> {
OccupiedEntry {
key: K,
value: V,
},
WouldEjectLru {
key: K,
value: V,
entry_size: usize,
free_memory: usize,
},
EntryTooLarge {
key: K,
value: V,
entry_size: usize,
max_size: usize,
},
}
Expand description
An enumeration of the different errors that can occur when calling LruCache::try_insert.
Variants§
OccupiedEntry
This error is raised if the cache already contained an entry with a key equal to the given one.
WouldEjectLru
This error is raised if the cache cannot fit the given entry without ejecting the LRU element.
EntryTooLarge
Fields
key: K
The key of the entry which was too large.
value: V
The value of the entry which was too large.
This error is raised if the amount of memory required to store an entry to be inserted is larger than the maximum of the cache.
Implementations§
source§impl<K, V> TryInsertError<K, V>
impl<K, V> TryInsertError<K, V>
sourcepub fn entry(&self) -> (&K, &V)
pub fn entry(&self) -> (&K, &V)
Gets references to the key and value of the entry for which LruCache::try_insert failed.
Example
use lru_mem::LruCache;
let mut cache = LruCache::new(1024);
cache.insert("apple", "sweet").unwrap();
let err = cache.try_insert("apple", "sour").unwrap_err();
assert_eq!((&"apple", &"sour"), err.entry());
sourcepub fn key(&self) -> &K
pub fn key(&self) -> &K
Gets a reference to the key of the entry for which LruCache::try_insert failed.
Example
use lru_mem::LruCache;
let mut cache = LruCache::new(1024);
cache.insert("apple", "sweet").unwrap();
let err = cache.try_insert("apple", "sour").unwrap_err();
assert_eq!(&"apple", err.key());
sourcepub fn value(&self) -> &V
pub fn value(&self) -> &V
Gets a reference to the value of the entry for which LruCache::try_insert failed.
Example
use lru_mem::LruCache;
let mut cache = LruCache::new(1024);
cache.insert("apple", "sweet").unwrap();
let err = cache.try_insert("apple", "sour").unwrap_err();
assert_eq!(&"sour", err.value());
sourcepub fn into_entry(self) -> (K, V)
pub fn into_entry(self) -> (K, V)
Takes ownership of the error and returns the key and value of the entry for which LruCache::try_insert failed.
Example
use lru_mem::LruCache;
let mut cache = LruCache::new(1024);
cache.insert("apple", "sweet").unwrap();
let err = cache.try_insert("apple", "sour").unwrap_err();
assert_eq!(("apple", "sour"), err.into_entry());
sourcepub fn into_key(self) -> K
pub fn into_key(self) -> K
Takes ownership of the error and returns the key of the entry for which LruCache::try_insert failed.
Example
use lru_mem::LruCache;
let mut cache = LruCache::new(1024);
cache.insert("apple", "sweet").unwrap();
let err = cache.try_insert("apple", "sour").unwrap_err();
assert_eq!("apple", err.into_key());
sourcepub fn into_value(self) -> V
pub fn into_value(self) -> V
Takes ownership of the error and returns the value of the entry for which LruCache::try_insert failed.
Example
use lru_mem::LruCache;
let mut cache = LruCache::new(1024);
cache.insert("apple", "sweet").unwrap();
let err = cache.try_insert("apple", "sour").unwrap_err();
assert_eq!("sour", err.into_value());
Trait Implementations§
source§impl<K: Clone, V: Clone> Clone for TryInsertError<K, V>
impl<K: Clone, V: Clone> Clone for TryInsertError<K, V>
source§fn clone(&self) -> TryInsertError<K, V>
fn clone(&self) -> TryInsertError<K, V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<K, V> Display for TryInsertError<K, V>
impl<K, V> Display for TryInsertError<K, V>
source§impl<K: Debug, V: Debug> Error for TryInsertError<K, V>
impl<K: Debug, V: Debug> Error for TryInsertError<K, V>
1.30.0 · source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
source§impl<K: PartialEq, V: PartialEq> PartialEq<TryInsertError<K, V>> for TryInsertError<K, V>
impl<K: PartialEq, V: PartialEq> PartialEq<TryInsertError<K, V>> for TryInsertError<K, V>
source§fn eq(&self, other: &TryInsertError<K, V>) -> bool
fn eq(&self, other: &TryInsertError<K, V>) -> bool
self
and other
values to be equal, and is used
by ==
.