diff --git a/crates/cross/src/dim/offset_dim_slice.rs b/crates/cross/src/dim/offset_dim_slice.rs index b49d293..34a4983 100644 --- a/crates/cross/src/dim/offset_dim_slice.rs +++ b/crates/cross/src/dim/offset_dim_slice.rs @@ -35,6 +35,14 @@ where } } +impl IntoIterator for OffsetDimSlice { + type Item = T::Item; + type IntoIter = T::IntoIter; + fn into_iter(self) -> Self::IntoIter { + self.inner.into_iter() + } +} + #[cfg(test)] mod test { use super::*; @@ -77,4 +85,30 @@ mod test { 300,40,50, ]); } + + #[test] + fn dim_slice_into_iter() { + let data = [1, 2, 3, 4]; + let s = OffsetDimSlice::new(Vec3u::new(1, 2, 3), Vec3u::new(2, 1, 2), &data); + let mut i = s.into_iter(); + assert_eq!(*i.next().unwrap(), 1); + assert_eq!(*i.next().unwrap(), 2); + assert_eq!(*i.next().unwrap(), 3); + assert_eq!(*i.next().unwrap(), 4); + assert_eq!(i.next(), None); + } + + #[test] + fn dim_slice_into_iter_mut() { + let mut data = [1, 2, 3, 4]; + let s = OffsetDimSlice::new(Vec3u::new(1, 2, 3), Vec3u::new(2, 1, 2), &mut data); + let mut i = s.into_iter(); + *i.next().unwrap() = 10; + assert_eq!(*i.next().unwrap(), 2); + *i.next().unwrap() += 27; + assert_eq!(*i.next().unwrap(), 4); + assert_eq!(i.next(), None); + + assert_eq!(data, [10,2,30,4]); + } }