Skip to content

hybrid-array: impl IntoIterator for references to all ArraySizes #957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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