OffsetDimSlice: impl IntoIter

This commit is contained in:
2022-08-17 21:20:24 -07:00
parent a247b861e1
commit 129aaadeac

View File

@@ -35,6 +35,14 @@ where
} }
} }
impl<T: IntoIterator> IntoIterator for OffsetDimSlice<T> {
type Item = T::Item;
type IntoIter = T::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.inner.into_iter()
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
@@ -77,4 +85,30 @@ mod test {
300,40,50, 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]);
}
} }