diff --git a/hybrid-array/src/lib.rs b/hybrid-array/src/lib.rs index 1212b2c1..d618b332 100644 --- a/hybrid-array/src/lib.rs +++ b/hybrid-array/src/lib.rs @@ -27,7 +27,7 @@ pub use typenum; pub use typenum::consts; use core::{ - array::{IntoIter, TryFromSliceError}, + array::TryFromSliceError, borrow::{Borrow, BorrowMut}, cmp::Ordering, fmt::{self, Debug}, @@ -307,6 +307,21 @@ where } } +impl IntoIterator for Array +where + U: ArraySize, +{ + type Item = T; + type IntoIter = as IntoIterator>::IntoIter; + + /// Creates a consuming iterator, that is, one that moves each value out of + /// the array (from start to end). The array cannot be used after calling + /// this unless `T` implements `Copy`, so the whole array is copied. + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + impl PartialEq for Array where T: PartialEq, @@ -495,9 +510,9 @@ impl ArrayExt for [T; N] { /// /// NOTE: do not implement this trait yourself. It is implemented for types in /// [`typenum::consts`]. -pub unsafe trait ArraySize: Unsigned { +pub unsafe trait ArraySize: Unsigned + 'static { /// Array type which corresponds to this size. - type ArrayType: ArrayExt + AsRef<[T]> + AsMut<[T]> + IntoArray; + type ArrayType: ArrayExt + AsRef<[T]> + AsMut<[T]> + IntoArray + IntoIterator; } /// Convert the given type into an [`Array`]. @@ -570,18 +585,6 @@ macro_rules! impl_array_size { } } - impl IntoIterator for Array { - type Item = T; - type IntoIter = IntoIter; - - /// Creates a consuming iterator, that is, one that moves each value out of - /// the array (from start to end). The array cannot be used after calling - /// this unless `T` implements `Copy`, so the whole array is copied. - fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() - } - } - impl<'a, T> IntoIterator for &'a Array { type Item = &'a T; type IntoIter = Iter<'a, T>;