urcu/collections/hashmap/
iterator.rs

1use crate::collections::hashmap::raw::RawIter;
2
3/// An iterator over the nodes of an [`RcuHashMap`].
4///
5/// [`RcuHashMap`]: crate::collections::hashmap::container::RcuHashMap
6pub struct Iter<'guard, K, V, F>(RawIter<'guard, K, V, F>)
7where
8    K: 'guard,
9    V: 'guard;
10
11impl<'guard, K, V, F> Iter<'guard, K, V, F> {
12    pub fn new(raw: RawIter<'guard, K, V, F>) -> Self {
13        Self(raw)
14    }
15}
16
17impl<'guard, K, V, F> Iterator for Iter<'guard, K, V, F> {
18    type Item = (&'guard K, &'guard V);
19
20    fn next(&mut self) -> Option<Self::Item> {
21        // SAFETY: The node pointer is convertible to a reference is non-null.
22        unsafe { self.0.get().as_ref() }.map(|entry| {
23            self.0.next();
24            entry.as_refs()
25        })
26    }
27}