Skip to content

Commit

Permalink
hybrid-array: impl IntoIterator for references to all ArraySizes (#…
Browse files Browse the repository at this point in the history
…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`.
  • Loading branch information
tarcieri authored Oct 8, 2023
1 parent 71ec948 commit eb03093
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions hybrid-array/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -322,6 +322,31 @@ where
}
}

impl<'a, T, U> IntoIterator for &'a Array<T, U>
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<T, U>
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<T, U> PartialEq for Array<T, U>
where
T: PartialEq,
Expand Down Expand Up @@ -584,25 +609,6 @@ macro_rules! impl_array_size {
Array::from_core_array(self)
}
}

impl<'a, T> IntoIterator for &'a Array<T, typenum::$ty> {
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<T, typenum::$ty> {
type Item = &'a mut T;
type IntoIter = IterMut<'a, T>;

#[inline]
fn into_iter(self) -> IterMut<'a, T> {
self.iter_mut()
}
}
)+
};
}
Expand Down

0 comments on commit eb03093

Please sign in to comment.