pub struct TypedLifecycle<K, F>{ /* private fields */ }Expand description
Helper for creating typed lifecycle implementations.
This wrapper provides convenient typed access to lifecycle events when you only use a single key type in your cache.
§Example
use priority_lfu::{TypedLifecycle, CacheBuilder, CacheKey, DeepSizeOf};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
#[derive(Hash, Eq, PartialEq, Clone)]
struct MyKey(u64);
#[derive(Clone, DeepSizeOf)]
struct MyValue(String);
impl CacheKey for MyKey {
type Value = MyValue;
}
let evict_count = Arc::new(AtomicUsize::new(0));
let counter = evict_count.clone();
let lifecycle = TypedLifecycle::<MyKey, _>::new(move |_key| {
counter.fetch_add(1, Ordering::Relaxed);
});
let cache = CacheBuilder::new(1024)
.lifecycle(lifecycle)
.build();Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<K, F> Freeze for TypedLifecycle<K, F>where
F: Freeze,
impl<K, F> RefUnwindSafe for TypedLifecycle<K, F>where
F: RefUnwindSafe,
impl<K, F> Send for TypedLifecycle<K, F>
impl<K, F> Sync for TypedLifecycle<K, F>
impl<K, F> Unpin for TypedLifecycle<K, F>where
F: Unpin,
impl<K, F> UnwindSafe for TypedLifecycle<K, F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more