pub struct LruCache<K, V, S = DefaultHashBuilder> { /* private fields */ }

Implementations§

source§

impl<K: Eq + Hash, V> LruCache<K, V>

source

pub fn new(capacity: usize) -> Self

source

pub fn new_unbounded() -> Self

Create a new unbounded LruCache that does not automatically evict entries.

A simple convenience method that is equivalent to LruCache::new(usize::MAX)

source§

impl<K, V, S> LruCache<K, V, S>

source

pub fn with_hasher(capacity: usize, hash_builder: S) -> Self

source

pub fn capacity(&self) -> usize

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn clear(&mut self)

source

pub fn iter(&self) -> Iter<'_, K, V>

source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

source

pub fn drain(&mut self) -> Drain<'_, K, V>

source§

impl<K: Eq + Hash, V, S> LruCache<K, V, S>
where S: BuildHasher,

source

pub fn contains_key<Q>(&mut self, key: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

source

pub fn insert(&mut self, k: K, v: V) -> Option<V>

Insert a new value into the LruCache.

If necessary, will remove the value at the front of the LRU list to make room.

source

pub fn peek<Q>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Get the value for the given key, without marking the value as recently used and moving it to the back of the LRU list.

source

pub fn peek_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Get the value for the given key mutably, without marking the value as recently used and moving it to the back of the LRU list.

source

pub fn get<Q>(&mut self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Retrieve the given key, marking it as recently used and moving it to the back of the LRU list.

source

pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Retrieve the given key, marking it as recently used and moving it to the back of the LRU list.

source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V, S>

If the returned entry is vacant, it will always have room to insert a single value. By using the entry API, you can exceed the configured capacity by 1.

The returned entry is not automatically moved to the back of the LRU list. By calling Entry::to_back / Entry::to_front you can manually control the position of this entry in the LRU list.

source

pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>

The constructed raw entry is never automatically moved to the back of the LRU list. By calling Entry::to_back / Entry::to_front you can manually control the position of this entry in the LRU list.

source

pub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>

If the constructed raw entry is vacant, it will always have room to insert a single value. By using the raw entry API, you can exceed the configured capacity by 1.

The constructed raw entry is never automatically moved to the back of the LRU list. By calling Entry::to_back / Entry::to_front you can manually control the position of this entry in the LRU list.

source

pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

source

pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

source

pub fn set_capacity(&mut self, capacity: usize)

Set the new cache capacity for the LruCache.

If there are more entries in the LruCache than the new capacity will allow, they are removed.

source

pub fn remove_lru(&mut self) -> Option<(K, V)>

Remove the least recently used entry and return it.

If the LruCache is empty this will return None.

Trait Implementations§

source§

impl<K: Hash + Eq + Clone, V: Clone, S: BuildHasher + Clone> Clone for LruCache<K, V, S>

source§

fn clone(&self) -> Self

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, V, S> Debug for LruCache<K, V, S>
where K: Debug, V: Debug,

source§

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

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

impl<K: Eq + Hash, V, S: BuildHasher> Extend<(K, V)> for LruCache<K, V, S>

source§

fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a, K, V, S> IntoIterator for &'a LruCache<K, V, S>

§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Iter<'a, K, V>

Creates an iterator from a value. Read more
source§

impl<'a, K, V, S> IntoIterator for &'a mut LruCache<K, V, S>

§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, K, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> IterMut<'a, K, V>

Creates an iterator from a value. Read more
source§

impl<K, V, S> IntoIterator for LruCache<K, V, S>

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> IntoIter<K, V>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<K, V, S> RefUnwindSafe for LruCache<K, V, S>

§

impl<K, V, S> Send for LruCache<K, V, S>
where K: Send, S: Send, V: Send,

§

impl<K, V, S> Sync for LruCache<K, V, S>
where K: Sync, S: Sync, V: Sync,

§

impl<K, V, S> Unpin for LruCache<K, V, S>
where S: Unpin,

§

impl<K, V, S> UnwindSafe for LruCache<K, V, S>

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> 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,

§

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