Replacement

Trait Replacement 

Source
pub trait Replacement<V, C: Capacity> {
    // Required method
    fn choose_for_replacement<'a>(
        &mut self,
        candidates: impl ExactSizeIterator<Item = (usize, &'a V)>,
    ) -> usize
       where V: 'a;

    // Provided methods
    fn on_hit(&self, value: &V) { ... }
    fn on_insert(&self, value: &V) { ... }
}
Expand description

Given that we need to replace a cache entry when inserting a new one, consider each (index, entry) pair and return the index whose entry should be replaced.

The given iterator will always be non-empty, and its indices will always be within the capacity, assuming the Indices that this is paired with is conformant.

Required Methods§

Source

fn choose_for_replacement<'a>( &mut self, candidates: impl ExactSizeIterator<Item = (usize, &'a V)>, ) -> usize
where V: 'a,

Choose which of the given cache entries will be replaced.

Provided Methods§

Source

fn on_hit(&self, value: &V)

Called whenever an existing cache entry is hit.

Source

fn on_insert(&self, value: &V)

Called whenever a new cache entry is inserted.

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.

Implementors§

Source§

impl<V, C> Replacement<V, C> for LruReplacement
where C: Capacity, V: LruTimestamp,

Source§

impl<V, C> Replacement<V, C> for RoundRobinReplacement
where C: Capacity,

Source§

impl<V, C, R> Replacement<V, C> for RandomReplacement<R>
where C: Capacity, R: Rng,

Available on crate feature rand only.