lockable/
map_like.rs

1use std::hash::Hash;
2
3pub enum GetOrInsertNoneResult<'a, V> {
4    Existing(&'a V),
5    Inserted(&'a V),
6}
7
8/// [MapLike] needs to be implemented for each kind of map we want to support, e.g.
9/// for [LruCache] and [HashMap]. This is the basis for that map becoming usable in a [LockableMapImpl]
10/// instance.
11pub trait MapLike<K, V>: IntoIterator<Item = (K, V)>
12where
13    K: Eq + PartialEq + Hash + Clone,
14{
15    type ItemIter<'a>: Iterator<Item = (&'a K, &'a V)>
16    where
17        Self: 'a,
18        K: 'a,
19        V: 'a;
20
21    fn new() -> Self;
22
23    fn len(&self) -> usize;
24
25    fn get_or_insert_none<'s>(&'s mut self, key: &K) -> GetOrInsertNoneResult<'s, V>;
26
27    fn get(&mut self, key: &K) -> Option<&V>;
28
29    fn remove(&mut self, key: &K) -> Option<V>;
30
31    fn iter(&self) -> Self::ItemIter<'_>;
32}