Struct rustls::limited_cache::LimitedCache
source · pub(crate) struct LimitedCache<K: Clone + Hash + Eq, V> {
map: HashMap<K, V>,
oldest: VecDeque<K>,
}
Expand description
A HashMap-alike, which never gets larger than a specified capacity, and evicts the oldest insertion to maintain this.
The requested capacity may be rounded up by the underlying collections. This implementation uses all the allocated storage.
This is inefficient: it stores keys twice.
Fields§
§map: HashMap<K, V>
§oldest: VecDeque<K>
Implementations§
source§impl<K, V> LimitedCache<K, V>
impl<K, V> LimitedCache<K, V>
sourcepub(crate) fn new(capacity_order_of_magnitude: usize) -> Self
pub(crate) fn new(capacity_order_of_magnitude: usize) -> Self
Create a new LimitedCache with the given rough capacity.
pub(crate) fn get_or_insert_default_and_edit( &mut self, k: K, edit: impl FnOnce(&mut V), )
pub(crate) fn insert(&mut self, k: K, v: V)
pub(crate) fn get<Q: Hash + Eq + ?Sized>(&self, k: &Q) -> Option<&V>where
K: Borrow<Q>,
pub(crate) fn get_mut<Q: Hash + Eq + ?Sized>(&mut self, k: &Q) -> Option<&mut V>where
K: Borrow<Q>,
pub(crate) fn remove<Q: Hash + Eq + ?Sized>(&mut self, k: &Q) -> Option<V>where
K: Borrow<Q>,
Auto Trait Implementations§
impl<K, V> Freeze for LimitedCache<K, V>
impl<K, V> RefUnwindSafe for LimitedCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for LimitedCache<K, V>
impl<K, V> Sync for LimitedCache<K, V>
impl<K, V> Unpin for LimitedCache<K, V>
impl<K, V> UnwindSafe for LimitedCache<K, V>where
K: UnwindSafe,
V: 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