From d3f627e7fdd122ef930b02c303a1e2e537fee9d8 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 1 Nov 2023 12:05:29 +0100 Subject: [PATCH 1/2] Remove opaque type on function iter() of IArray --- src/array.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/array.rs b/src/array.rs index bc27342..7773c11 100644 --- a/src/array.rs +++ b/src/array.rs @@ -83,6 +83,27 @@ impl From<[T; 1]> for IArray { } } +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 +120,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 From 2c314d090e16019fac613888c0bb35561e7aa119 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 1 Nov 2023 12:09:17 +0100 Subject: [PATCH 2/2] clippy --- src/array.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/array.rs b/src/array.rs index 7773c11..cf20ca7 100644 --- a/src/array.rs +++ b/src/array.rs @@ -83,6 +83,7 @@ impl From<[T; 1]> for IArray { } } +#[derive(Debug)] pub struct Iter { array: IArray, index: usize,