Skip to content

Commit eb03093

Browse files
authored
hybrid-array: impl IntoIterator for references to all ArraySizes (#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`.
1 parent 71ec948 commit eb03093

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

hybrid-array/src/lib.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ where
6666

6767
/// Returns an iterator over the array.
6868
#[inline]
69-
fn iter(&self) -> Iter<'_, T> {
69+
pub fn iter(&self) -> Iter<'_, T> {
7070
self.as_ref().iter()
7171
}
7272

7373
/// Returns an iterator that allows modifying each value.
7474
#[inline]
75-
fn iter_mut(&mut self) -> IterMut<'_, T> {
75+
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
7676
self.as_mut().iter_mut()
7777
}
7878

@@ -322,6 +322,31 @@ where
322322
}
323323
}
324324

325+
impl<'a, T, U> IntoIterator for &'a Array<T, U>
326+
where
327+
U: ArraySize,
328+
{
329+
type Item = &'a T;
330+
type IntoIter = Iter<'a, T>;
331+
332+
fn into_iter(self) -> Iter<'a, T> {
333+
self.iter()
334+
}
335+
}
336+
337+
impl<'a, T, U> IntoIterator for &'a mut Array<T, U>
338+
where
339+
U: ArraySize,
340+
{
341+
type Item = &'a mut T;
342+
type IntoIter = IterMut<'a, T>;
343+
344+
#[inline]
345+
fn into_iter(self) -> IterMut<'a, T> {
346+
self.iter_mut()
347+
}
348+
}
349+
325350
impl<T, U> PartialEq for Array<T, U>
326351
where
327352
T: PartialEq,
@@ -584,25 +609,6 @@ macro_rules! impl_array_size {
584609
Array::from_core_array(self)
585610
}
586611
}
587-
588-
impl<'a, T> IntoIterator for &'a Array<T, typenum::$ty> {
589-
type Item = &'a T;
590-
type IntoIter = Iter<'a, T>;
591-
592-
fn into_iter(self) -> Iter<'a, T> {
593-
self.iter()
594-
}
595-
}
596-
597-
impl<'a, T> IntoIterator for &'a mut Array<T, typenum::$ty> {
598-
type Item = &'a mut T;
599-
type IntoIter = IterMut<'a, T>;
600-
601-
#[inline]
602-
fn into_iter(self) -> IterMut<'a, T> {
603-
self.iter_mut()
604-
}
605-
}
606612
)+
607613
};
608614
}

0 commit comments

Comments
 (0)