diff --git a/src/array.rs b/src/array.rs index bc27342..cf20ca7 100644 --- a/src/array.rs +++ b/src/array.rs @@ -83,6 +83,28 @@ impl From<[T; 1]> for IArray { } } +#[derive(Debug)] +pub struct Iter { + array: IArray, + index: usize, +} + +impl Iter { + fn new(array: IArray) -> Self { + Self { array, index: 0 } + } +} + +impl Iterator for Iter { + type Item = T; + + fn next(&mut self) -> Option { + let item = self.array.get(self.index); + self.index += 1; + item + } +} + impl IArray { /// Returns an iterator over the slice. /// @@ -99,12 +121,8 @@ impl IArray { /// assert_eq!(iterator.next(), None); /// ``` #[inline] - pub fn iter(&self) -> impl Iterator + '_ { - match self { - Self::Static(a) => a.iter().cloned(), - Self::Rc(a) => a.iter().cloned(), - Self::Single(a) => a.iter().cloned(), - } + pub fn iter(&self) -> Iter { + Iter::new(self.clone()) } /// Returns the number of elements in the vector, also referred to