pub trait Policy<K, V>: Sized {
type Inner: Prune<K, V, Self>;
// Required methods
fn lock_inner(&self) -> MutexGuard<'_, Self::Inner>;
fn get<S: BuildHasher>(
&self,
key: &K,
cache: &LightCache<K, V, S, Self>,
) -> Option<V>;
fn insert<S: BuildHasher>(
&self,
key: K,
value: V,
cache: &LightCache<K, V, S, Self>,
) -> Option<V>;
fn remove<S: BuildHasher>(
&self,
key: &K,
cache: &LightCache<K, V, S, Self>,
) -> Option<V>;
// Provided method
fn lock_and_prune<S: BuildHasher>(
&self,
cache: &LightCache<K, V, S, Self>,
) -> MutexGuard<'_, Self::Inner> { ... }
}Expand description
A Policy augments accsess to a LightCache instance, managing the entry and eviction of items in the cache.
A policy usally requires shared mutable state, therefore the Policy::Inner type is used to represent this.
Required Associated Types§
Required Methods§
Sourcefn lock_inner(&self) -> MutexGuard<'_, Self::Inner>
fn lock_inner(&self) -> MutexGuard<'_, Self::Inner>
§Panics
This method will panic if the lock is poisoned
fn get<S: BuildHasher>( &self, key: &K, cache: &LightCache<K, V, S, Self>, ) -> Option<V>
fn insert<S: BuildHasher>( &self, key: K, value: V, cache: &LightCache<K, V, S, Self>, ) -> Option<V>
fn remove<S: BuildHasher>( &self, key: &K, cache: &LightCache<K, V, S, Self>, ) -> Option<V>
Provided Methods§
fn lock_and_prune<S: BuildHasher>( &self, cache: &LightCache<K, V, S, Self>, ) -> MutexGuard<'_, Self::Inner>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.