micro_moka/unsync/
iter.rs1use super::{Cache, ValueEntry};
2
3use std::{
4 hash::Hash,
5 rc::Rc,
6};
7
8type HashMapIter<'i, K, V> = std::collections::hash_map::Iter<'i, Rc<K>, ValueEntry<K, V>>;
9
10pub struct Iter<'i, K, V> {
11 iter: HashMapIter<'i, K, V>,
12}
13
14impl<'i, K, V> Iter<'i, K, V> {
15 pub(crate) fn new(_cache: &'i Cache<K, V, impl std::hash::BuildHasher>, iter: HashMapIter<'i, K, V>) -> Self {
16 Self { iter }
17 }
18}
19
20impl<'i, K, V> Iterator for Iter<'i, K, V>
21where
22 K: Hash + Eq,
23{
24 type Item = (&'i K, &'i V);
25
26 fn next(&mut self) -> Option<Self::Item> {
27 if let Some((k, entry)) = self.iter.next() {
28 return Some((k, &entry.value));
29 }
30 None
31 }
32}