1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::ConcurrentIter;

/// A regular `Iterator` crated from the [`ConcurrentIter::ids_and_values`] method.
///
/// Its `next` method does nothing but call [`ConcurrentIter::next_id_and_value`] method.
/// This iterator is a wrapper to allow using the concurrent iterator in a `for` loop directly.
pub struct ConIterIdsAndValues<'a, C>
where
    C: ConcurrentIter,
{
    con_iter: &'a C,
}

impl<'a, C: ConcurrentIter> From<&'a C> for ConIterIdsAndValues<'a, C> {
    fn from(con_iter: &'a C) -> Self {
        Self { con_iter }
    }
}

impl<'a, C> Iterator for ConIterIdsAndValues<'a, C>
where
    C: ConcurrentIter,
{
    type Item = (usize, C::Item);

    #[inline(always)]
    fn next(&mut self) -> Option<Self::Item> {
        self.con_iter.next_id_and_value().map(|x| (x.idx, x.value))
    }
}