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

Fields

key: K

The key of the entry to insert.

value: V

The value of the entry to insert.

This error is raised if the cache already contained an entry with a key equal to the given one.

WouldEjectLru

Fields

key: K

The key of the entry to insert.

value: V

The value of the entry to insert.

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

key: K

The key of the entry which was too large.

value: V

The value of the entry which was too large.

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());

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());

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The lower-level source of this error, if any. Read more

🔬 This is a nightly-only experimental API. (backtrace)

Returns a stack backtrace, if available, of where this error occurred. Read more

👎 Deprecated since 1.42.0:

use the Display impl or to_string()

👎 Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.