Trait caches::Cache

source ·
pub trait Cache<K: Hash + Eq, V> {
    fn put(&mut self, k: K, v: V) -> PutResult<K, V>;
    fn get<'a, Q>(&mut self, k: &'a Q) -> Option<&'a V>
    where
        KeyRef<K>: Borrow<Q>,
        Q: Eq + Hash + ?Sized
; fn get_mut<'a, Q>(&mut self, k: &'a Q) -> Option<&'a mut V>
    where
        KeyRef<K>: Borrow<Q>,
        Q: Eq + Hash + ?Sized
; fn peek<'a, Q>(&self, k: &'a Q) -> Option<&'a V>
    where
        KeyRef<K>: Borrow<Q>,
        Q: Eq + Hash + ?Sized
; fn peek_mut<'a, Q>(&mut self, k: &'a Q) -> Option<&'a mut V>
    where
        KeyRef<K>: Borrow<Q>,
        Q: Eq + Hash + ?Sized
; fn contains<Q>(&self, k: &Q) -> bool
    where
        KeyRef<K>: Borrow<Q>,
        Q: Eq + Hash + ?Sized
; fn remove<Q>(&mut self, k: &Q) -> Option<V>
    where
        KeyRef<K>: Borrow<Q>,
        Q: Eq + Hash + ?Sized
; fn purge(&mut self); fn len(&self) -> usize; fn cap(&self) -> usize; fn is_empty(&self) -> bool; }
Expand description

Cache contains the basic APIs for a cache. All of caches in this crate implement this trait.

Required Methods

Puts a key-value pair into cache, returns a PutResult.

Returns a reference to the value of the key in the cache or None if it is not present in the cache. Update the cache if it exists.

Returns a mutable reference to the value of the key in the cache or None if it is not present in the cache. Update the cache if it exists.

Returns a reference to the value corresponding to the key in the cache or None if it is not present in the cache. Unlike get, peek does not update the cache so the key’s position will be unchanged.

Returns a mutable reference to the value corresponding to the key in the cache or None if it is not present in the cache. Unlike get_mut, peek_mut does not update the cache so the key’s position will be unchanged.

Returns a bool indicating whether the given key is in the cache. Does not update the cache.

Removes and returns the value corresponding to the key from the cache or None if it does not exist.

Clears the contents of the cache.

Returns the number of key-value pairs that are currently in the the cache.

Returns the maximum number of key-value pairs the cache can hold.

Returns a bool indicating whether the cache is empty or not.

Implementors