LocalCache

Struct LocalCache 

Source
pub struct LocalCache<K, V, H> { /* private fields */ }
Expand description

When immutable cache access is required, use this LocalCache to store evicted values. Then when you get mutable cache access, call into_iter to update the cache manually.

This cache comes with a price: the values will be boxed in order to provide stable borrows. Ideally, it should be cheap to box your values, i.e. most of their data should already be on the heap.

Implementations§

Source§

impl<K, V, H> LocalCache<K, V, H>
where K: Eq + Hash, H: Default + BuildHasher,

Source

pub fn new() -> Self

Source

pub fn remember_cached_access(&self, key: K)

Source

pub fn get_or_insert_with(&self, key: K, f: impl FnOnce() -> V) -> &V

Source

pub fn into_iter(self) -> impl Iterator<Item = (K, LocalAccess<V>)>

Trait Implementations§

Source§

impl<K: Default, V: Default, H: Default> Default for LocalCache<K, V, H>

Source§

fn default() -> LocalCache<K, V, H>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V, H> !Freeze for LocalCache<K, V, H>

§

impl<K, V, H> !RefUnwindSafe for LocalCache<K, V, H>

§

impl<K, V, H> Send for LocalCache<K, V, H>
where H: Send, K: Send, V: Send,

§

impl<K, V, H> !Sync for LocalCache<K, V, H>

§

impl<K, V, H> Unpin for LocalCache<K, V, H>
where H: Unpin, K: Unpin,

§

impl<K, V, H> UnwindSafe for LocalCache<K, V, H>
where K: UnwindSafe, H: 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> 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, 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.