urcu/collections/list/
iterator.rs

1use std::ops::Deref;
2
3use crate::collections::list::raw::RawIter;
4use crate::rcu::guard::RcuGuard;
5
6/// An iterator over the nodes of an [`RcuList`].
7///
8/// [`RcuList`]: crate::collections::list::container::RcuList
9pub struct Iter<'guard, T, G, const FORWARD: bool>
10where
11    G: RcuGuard,
12{
13    raw: RawIter<T, FORWARD>,
14    #[allow(dead_code)]
15    guard: &'guard G,
16}
17
18impl<'guard, T, G, const FORWARD: bool> Iter<'guard, T, G, FORWARD>
19where
20    G: RcuGuard,
21{
22    pub(crate) fn new(raw: RawIter<T, FORWARD>, guard: &'guard G) -> Self {
23        Self { raw, guard }
24    }
25}
26
27impl<'guard, T, G, const FORWARD: bool> Iterator for Iter<'guard, T, G, FORWARD>
28where
29    Self: 'guard,
30    G: RcuGuard,
31{
32    type Item = &'guard T;
33
34    fn next(&mut self) -> Option<Self::Item> {
35        // SAFETY: The RCU critical section is enforced.
36        unsafe { self.raw.next().as_ref() }.map(|node| node.deref())
37    }
38}