Skip to content

Commit b6df4b6

Browse files
committed
impl FromIterator/IntoIterator for Aligned
1 parent 10a449d commit b6df4b6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/lib.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,58 @@ where
457457
}
458458
}
459459

460+
impl<A, T, U> FromIterator<U> for Aligned<A, T>
461+
where
462+
A: Alignment,
463+
T: FromIterator<U>,
464+
{
465+
fn from_iter<I: IntoIterator<Item = U>>(iter: I) -> Self {
466+
Self {
467+
_alignment: [],
468+
value: T::from_iter(iter),
469+
}
470+
}
471+
}
472+
473+
impl<A, T> IntoIterator for Aligned<A, T>
474+
where
475+
A: Alignment,
476+
T: IntoIterator,
477+
{
478+
type IntoIter = T::IntoIter;
479+
type Item = T::Item;
480+
481+
fn into_iter(self) -> Self::IntoIter {
482+
self.value.into_iter()
483+
}
484+
}
485+
486+
impl<'a, A, T> IntoIterator for &'a Aligned<A, T>
487+
where
488+
A: Alignment,
489+
&'a T: IntoIterator,
490+
{
491+
type IntoIter = <&'a T as IntoIterator>::IntoIter;
492+
type Item = <&'a T as IntoIterator>::Item;
493+
494+
fn into_iter(self) -> Self::IntoIter {
495+
(&self.value).into_iter()
496+
}
497+
}
498+
499+
impl<'a, A, T> IntoIterator for &'a mut Aligned<A, T>
500+
where
501+
A: Alignment,
502+
&'a mut T: IntoIterator,
503+
{
504+
type IntoIter = <&'a mut T as IntoIterator>::IntoIter;
505+
type Item = <&'a mut T as IntoIterator>::Item;
506+
507+
fn into_iter(self) -> Self::IntoIter {
508+
(&mut self.value).into_iter()
509+
}
510+
}
511+
460512
#[test]
461513
fn sanity() {
462514
use core::mem;

0 commit comments

Comments
 (0)