A better Rust ATProto crate
1

Configure Feed

Select the types of activity you want to include in your feed.

at main 822 B View raw
1use super::{Cache, ValueEntry}; 2 3use std::{ 4 hash::{BuildHasher, 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, S> { 11 cache: &'i Cache<K, V, S>, 12 iter: HashMapIter<'i, K, V>, 13} 14 15impl<'i, K, V, S> Iter<'i, K, V, S> { 16 pub(crate) fn new(cache: &'i Cache<K, V, S>, iter: HashMapIter<'i, K, V>) -> Self { 17 Self { cache, iter } 18 } 19} 20 21impl<'i, K, V, S> Iterator for Iter<'i, K, V, S> 22where 23 K: Hash + Eq, 24 S: BuildHasher + Clone, 25{ 26 type Item = (&'i K, &'i V); 27 28 fn next(&mut self) -> Option<Self::Item> { 29 for (k, entry) in self.iter.by_ref() { 30 if !self.cache.is_expired_entry(entry) { 31 return Some((k, &entry.value)); 32 } 33 } 34 None 35 } 36}