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.
Variants
OccupiedEntry
This error is raised if the cache already contained an entry with a key equal to the given one.
WouldEjectLru
Fields
entry_size: usize
The computed size requirement of the entry if it were in the cache in bytes.
free_memory: usize
The remaining free memory of the cache in bytes.
This error is raised if the cache cannot fit the given entry without ejecting the LRU element.
EntryTooLarge
Fields
entry_size: usize
The computed size requirement of the entry if it were in the cache in bytes.
max_size: usize
The maximum size of the cache in bytes.
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
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());
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());
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());
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());
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());
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
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl<K, V> RefUnwindSafe for TryInsertError<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for TryInsertError<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for TryInsertError<K, V> where
K: Sync,
V: Sync,
impl<K, V> Unpin for TryInsertError<K, V> where
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for TryInsertError<K, V> where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more