From b6df4b600ddc453cdadc7f6002e63fe6d60c20f8 Mon Sep 17 00:00:00 2001 From: novacrazy Date: Sat, 18 Oct 2025 13:45:08 -0500 Subject: [PATCH] impl FromIterator/IntoIterator for Aligned --- src/lib.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0caeabc..e203fd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -457,6 +457,58 @@ where } } +impl FromIterator for Aligned +where + A: Alignment, + T: FromIterator, +{ + fn from_iter>(iter: I) -> Self { + Self { + _alignment: [], + value: T::from_iter(iter), + } + } +} + +impl IntoIterator for Aligned +where + A: Alignment, + T: IntoIterator, +{ + type IntoIter = T::IntoIter; + type Item = T::Item; + + fn into_iter(self) -> Self::IntoIter { + self.value.into_iter() + } +} + +impl<'a, A, T> IntoIterator for &'a Aligned +where + A: Alignment, + &'a T: IntoIterator, +{ + type IntoIter = <&'a T as IntoIterator>::IntoIter; + type Item = <&'a T as IntoIterator>::Item; + + fn into_iter(self) -> Self::IntoIter { + (&self.value).into_iter() + } +} + +impl<'a, A, T> IntoIterator for &'a mut Aligned +where + A: Alignment, + &'a mut T: IntoIterator, +{ + type IntoIter = <&'a mut T as IntoIterator>::IntoIter; + type Item = <&'a mut T as IntoIterator>::Item; + + fn into_iter(self) -> Self::IntoIter { + (&mut self.value).into_iter() + } +} + #[test] fn sanity() { use core::mem;