Enum 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.

Fields

§key: K

The key of the entry to insert.

§value: V

The value of the entry to insert.

§

WouldEjectLru

This error is raised if the cache cannot fit the given entry without ejecting the LRU element.

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.

§

EntryTooLarge

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.

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.

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 duplicate 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)>

Returns 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, request: &mut Request<'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 for TryInsertError<K, V>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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> StructuralPartialEq for TryInsertError<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for TryInsertError<K, V>
where K: Freeze, V: Freeze,

§

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

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where 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 T
where 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<T> ToOwned for T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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>) -> usize
where 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>, ) -> usize
where 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