orx_iterable/transformations/
enumerated.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::Iterable;

/// Wraps an `Iterable` and creates a new `Iterable` which yields the element indices
/// together with the elements.
pub struct Enumerated<I>
where
    I: Iterable,
{
    pub(crate) it: I,
}

impl<I> Iterable for Enumerated<I>
where
    I: Iterable,
{
    type Item = (usize, I::Item);

    type Iter = core::iter::Enumerate<I::Iter>;

    fn iter(&self) -> Self::Iter {
        self.it.iter().enumerate()
    }
}