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

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§

source§

impl<K, V> TryInsertError<K, V>

source

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

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

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

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

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

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>

source§

fn clone(&self) -> TryInsertError<K, V>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K: Debug, V: Debug> Debug for TryInsertError<K, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K, V> Display for TryInsertError<K, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: Debug, V: Debug> Error for TryInsertError<K, V>

1.30.0 · source§

fn source(&self) -> Option<&(dyn Error + 'static)>

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

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, demand: &mut Demand<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
source§

impl<K: PartialEq, V: PartialEq> PartialEq<TryInsertError<K, V>> for TryInsertError<K, V>

source§

fn eq(&self, other: &TryInsertError<K, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K: Eq, V: Eq> Eq for TryInsertError<K, V>

source§

impl<K, V> StructuralEq for TryInsertError<K, V>

source§

impl<K, V> StructuralPartialEq for TryInsertError<K, V>

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<E> Provider for Ewhere E: Error + ?Sized,

source§

fn provide<'a>(&'a self, demand: &mut Demand<'a>)

🔬This is a nightly-only experimental API. (provide_any)
Data providers should implement this method to provide all values they are able to provide by using demand. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ValueSize for T

source§

fn value_size(&self) -> usize

The size of this value in bytes, excluding allocated data. Read more
source§

fn value_size_sum_iter<'item>(iterator: impl Iterator<Item = &'item T>) -> usizewhere T: 'item,

The total sum of the sizes of all values in the given iterator, in bytes. This is default-implemented by computing ValueSize::value_size on every element and summing them. For Sized types, a more potentially efficient implementation using Iterator::count is provided. If you are implementing this trait manually, it is unlikely to be more efficient to provide a manual implementation here. Read more
source§

fn value_size_sum_exact_size_iter<'item>( iterator: impl ExactSizeIterator<Item = &'item T> ) -> usizewhere T: 'item,

The total sum of the sizes of all values in the given exact-size-iterator, in bytes. This is default-implemented by using ValueSize::value_size_sum_iter. For Sized types, a usually more efficient implementation using ExactSizeIterator::len is provided. If you are implementing this trait manually, it is unlikely to be more efficient to provide a manual implementation here. Read more