From eb03093d97e2f2a61c4bf1135a2492af343ccaa3 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sun, 8 Oct 2023 11:03:54 -0600 Subject: [PATCH] hybrid-array: impl `IntoIterator` for references to all `ArraySize`s (#957) Switches from a special case impl per size to one which is generic over all array sizes, similar to what #956 did for the owning implementation of `IntoIterator`. --- hybrid-array/src/lib.rs | 48 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/hybrid-array/src/lib.rs b/hybrid-array/src/lib.rs index d618b332..e4817adc 100644 --- a/hybrid-array/src/lib.rs +++ b/hybrid-array/src/lib.rs @@ -66,13 +66,13 @@ where /// Returns an iterator over the array. #[inline] - fn iter(&self) -> Iter<'_, T> { + pub fn iter(&self) -> Iter<'_, T> { self.as_ref().iter() } /// Returns an iterator that allows modifying each value. #[inline] - fn iter_mut(&mut self) -> IterMut<'_, T> { + pub fn iter_mut(&mut self) -> IterMut<'_, T> { self.as_mut().iter_mut() } @@ -322,6 +322,31 @@ where } } +impl<'a, T, U> IntoIterator for &'a Array +where + U: ArraySize, +{ + type Item = &'a T; + type IntoIter = Iter<'a, T>; + + fn into_iter(self) -> Iter<'a, T> { + self.iter() + } +} + +impl<'a, T, U> IntoIterator for &'a mut Array +where + U: ArraySize, +{ + type Item = &'a mut T; + type IntoIter = IterMut<'a, T>; + + #[inline] + fn into_iter(self) -> IterMut<'a, T> { + self.iter_mut() + } +} + impl PartialEq for Array where T: PartialEq, @@ -584,25 +609,6 @@ macro_rules! impl_array_size { Array::from_core_array(self) } } - - impl<'a, T> IntoIterator for &'a Array { - type Item = &'a T; - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Iter<'a, T> { - self.iter() - } - } - - impl<'a, T> IntoIterator for &'a mut Array { - type Item = &'a mut T; - type IntoIter = IterMut<'a, T>; - - #[inline] - fn into_iter(self) -> IterMut<'a, T> { - self.iter_mut() - } - } )+ }; }