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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::*;

/// Immutable `Arrav` iterator
///
/// This struct is created using [`Arrav::iter`].
#[derive(Debug, Copy, Clone)]
pub struct ArravIter<T, const N: usize>
where
    T: Copy + Sentinel,
    [T; N]: core::array::LengthAtMost32,
{
    v: Arrav<T, N>,
    at: usize,
}

impl<T, const N: usize> IntoIterator for Arrav<T, N>
where
    T: Copy + Sentinel,
    [T; N]: core::array::LengthAtMost32,
{
    type IntoIter = ArravIter<T, N>;
    type Item = T;
    fn into_iter(self) -> Self::IntoIter {
        ArravIter::new(self)
    }
}

impl<T, const N: usize> ArravIter<T, N>
where
    T: Copy + Sentinel,
    [T; N]: core::array::LengthAtMost32,
{
    pub(crate) const fn new(v: Arrav<T, N>) -> Self {
        Self { v, at: 0 }
    }
}

impl<T, const N: usize> Iterator for ArravIter<T, N>
where
    T: Copy + Sentinel,
    [T; N]: core::array::LengthAtMost32,
{
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        let t = *self.v.get(self.at)?;
        self.at += 1;
        Some(t)
    }
}

impl<'a, T, const N: usize> IntoIterator for &'a Arrav<T, N>
where
    T: Copy + Sentinel,
    [T; N]: core::array::LengthAtMost32,
{
    type IntoIter = ArravIter<T, N>;
    type Item = T;
    fn into_iter(self) -> Self::IntoIter {
        Arrav::into_iter(*self)
    }
}