diff --git a/palette/src/alpha/alpha.rs b/palette/src/alpha/alpha.rs index e1e92351c..c75b80b51 100644 --- a/palette/src/alpha/alpha.rs +++ b/palette/src/alpha/alpha.rs @@ -864,58 +864,6 @@ where } } -impl IntoIterator for Alpha -where - C: IntoIterator, - A: IntoIterator, -{ - type Item = Alpha; - - type IntoIter = Iter; - - fn into_iter(self) -> Self::IntoIter { - Iter { - color: self.color.into_iter(), - alpha: self.alpha.into_iter(), - } - } -} - -impl<'a, C, A> IntoIterator for &'a Alpha -where - &'a C: IntoIterator, - &'a A: IntoIterator, -{ - type Item = Alpha<<&'a C as IntoIterator>::Item, <&'a A as IntoIterator>::Item>; - - type IntoIter = Iter<<&'a C as IntoIterator>::IntoIter, <&'a A as IntoIterator>::IntoIter>; - - fn into_iter(self) -> Self::IntoIter { - Iter { - color: (&self.color).into_iter(), - alpha: (&self.alpha).into_iter(), - } - } -} - -impl<'a, C, A> IntoIterator for &'a mut Alpha -where - &'a mut C: IntoIterator, - &'a mut A: IntoIterator, -{ - type Item = Alpha<<&'a mut C as IntoIterator>::Item, <&'a mut A as IntoIterator>::Item>; - - type IntoIter = - Iter<<&'a mut C as IntoIterator>::IntoIter, <&'a mut A as IntoIterator>::IntoIter>; - - fn into_iter(self) -> Self::IntoIter { - Iter { - color: (&mut self.color).into_iter(), - alpha: (&mut self.alpha).into_iter(), - } - } -} - /// An iterator for transparent colors. pub struct Iter { pub(crate) color: C, diff --git a/palette/src/cast/array.rs b/palette/src/cast/array.rs index e55b6ac20..25c9e9f2d 100644 --- a/palette/src/cast/array.rs +++ b/palette/src/cast/array.rs @@ -1,6 +1,6 @@ use core::mem::{transmute_copy, ManuallyDrop}; -#[cfg(feature = "alloc")] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::{boxed::Box, vec::Vec}; pub use palette_derive::ArrayCast; diff --git a/palette/src/hsl.rs b/palette/src/hsl.rs index f478a88ba..7bc4591fa 100644 --- a/palette/src/hsl.rs +++ b/palette/src/hsl.rs @@ -533,9 +533,6 @@ unsafe impl bytemuck::Pod for Hsl where T: bytemuck::Pod {} mod test { use super::Hsl; - #[cfg(feature = "alloc")] - use crate::Srgb; - test_convert_into_from_xyz!(Hsl); #[cfg(feature = "approx")] @@ -622,24 +619,12 @@ mod test { } struct_of_arrays_tests!( - Hsl, - Hsl::new(0.1f32, 0.2, 0.3), - Hsl::new(0.2, 0.3, 0.4), - Hsl::new(0.3, 0.4, 0.5) + Hsl[hue, saturation, lightness] phantom: standard, + super::Hsla::new(0.1f32, 0.2, 0.3, 0.4), + super::Hsla::new(0.2, 0.3, 0.4, 0.5), + super::Hsla::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{encoding::Srgb, hsl::Hsla}; - - struct_of_arrays_tests!( - Hsla, - Hsla::new(0.1f32, 0.2, 0.3, 0.4), - Hsla::new(0.2, 0.3, 0.4, 0.5), - Hsla::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/hsluv.rs b/palette/src/hsluv.rs index 13b90e8da..b025d13a6 100644 --- a/palette/src/hsluv.rs +++ b/palette/src/hsluv.rs @@ -345,24 +345,12 @@ mod test { } struct_of_arrays_tests!( - Hsluv, - Hsluv::new(0.1f32, 0.2, 0.3), - Hsluv::new(0.2, 0.3, 0.4), - Hsluv::new(0.3, 0.4, 0.5) + Hsluv[hue, saturation, l] phantom: white_point, + super::Hsluva::new(0.1f32, 0.2, 0.3, 0.4), + super::Hsluva::new(0.2, 0.3, 0.4, 0.5), + super::Hsluva::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{hsluv::Hsluva, white_point::D65}; - - struct_of_arrays_tests!( - Hsluva, - Hsluva::new(0.1f32, 0.2, 0.3, 0.4), - Hsluva::new(0.2, 0.3, 0.4, 0.5), - Hsluva::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/hsv.rs b/palette/src/hsv.rs index 1a5bb01f4..6188bd7ff 100644 --- a/palette/src/hsv.rs +++ b/palette/src/hsv.rs @@ -540,9 +540,6 @@ unsafe impl bytemuck::Pod for Hsv where T: bytemuck::Pod {} mod test { use super::Hsv; - #[cfg(feature = "alloc")] - use crate::Srgb; - test_convert_into_from_xyz!(Hsv); #[cfg(feature = "approx")] @@ -629,24 +626,12 @@ mod test { } struct_of_arrays_tests!( - Hsv, - Hsv::new(0.1f32, 0.2, 0.3), - Hsv::new(0.2, 0.3, 0.4), - Hsv::new(0.3, 0.4, 0.5) + Hsv[hue, saturation, value] phantom: standard, + super::Hsva::new(0.1f32, 0.2, 0.3, 0.4), + super::Hsva::new(0.2, 0.3, 0.4, 0.5), + super::Hsva::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{encoding::Srgb, hsv::Hsva}; - - struct_of_arrays_tests!( - Hsva, - Hsva::new(0.1f32, 0.2, 0.3, 0.4), - Hsva::new(0.2, 0.3, 0.4, 0.5), - Hsva::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/hues.rs b/palette/src/hues.rs index 2fdfbcaef..6505574b6 100644 --- a/palette/src/hues.rs +++ b/palette/src/hues.rs @@ -3,10 +3,7 @@ #[cfg(any(feature = "approx", feature = "random"))] use core::ops::Mul; -use core::{ - cmp::PartialEq, - ops::{Add, AddAssign, Neg, Sub, SubAssign}, -}; +use core::ops::{Add, AddAssign, Neg, Sub, SubAssign}; #[cfg(feature = "approx")] use approx::{AbsDiffEq, RelativeEq, UlpsEq}; @@ -582,9 +579,40 @@ macro_rules! make_hues { } } - impl IntoIterator for $name where C: IntoIterator { - type Item = $name; - type IntoIter = $iter_name; + impl IntoIterator for $name<[T; N]> { + type Item = $name; + type IntoIter = $iter_name>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + $iter_name(IntoIterator::into_iter(self.0)) + } + } + + impl<'a, T> IntoIterator for $name<&'a [T]> { + type Item = $name<&'a T>; + type IntoIter = $iter_name>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + $iter_name(self.0.into_iter()) + } + } + + impl<'a, T> IntoIterator for $name<&'a mut [T]> { + type Item = $name<&'a mut T>; + type IntoIter = $iter_name>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + $iter_name(self.0.into_iter()) + } + } + + #[cfg(feature = "alloc")] + impl IntoIterator for $name> { + type Item = $name; + type IntoIter = $iter_name>; #[inline(always)] fn into_iter(self) -> Self::IntoIter { @@ -592,9 +620,19 @@ macro_rules! make_hues { } } - impl<'a, C> IntoIterator for &'a $name where &'a C: IntoIterator { - type Item = $name<<&'a C as IntoIterator>::Item>; - type IntoIter = $iter_name<<&'a C as IntoIterator>::IntoIter>; + impl<'a, T, const N: usize> IntoIterator for &'a $name<[T; N]> { + type Item = $name<&'a T>; + type IntoIter = $iter_name>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + $iter_name((&self.0).into_iter()) + } + } + + impl<'a, 'b, T> IntoIterator for &'a $name<&'b [T]> { + type Item = $name<&'a T>; + type IntoIter = $iter_name>; #[inline(always)] fn into_iter(self) -> Self::IntoIter { @@ -602,9 +640,51 @@ macro_rules! make_hues { } } - impl<'a, C> IntoIterator for &'a mut $name where &'a mut C: IntoIterator { - type Item = $name<<&'a mut C as IntoIterator>::Item>; - type IntoIter = $iter_name<<&'a mut C as IntoIterator>::IntoIter>; + impl<'a, 'b, T> IntoIterator for &'a $name<&'b mut [T]> { + type Item = $name<&'a T>; + type IntoIter = $iter_name>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + $iter_name((&*self.0).into_iter()) + } + } + + #[cfg(feature = "alloc")] + impl<'a, T> IntoIterator for &'a $name> { + type Item = $name<&'a T>; + type IntoIter = $iter_name>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + $iter_name((&self.0).into_iter()) + } + } + + #[cfg(feature = "alloc")] + impl<'a, T> IntoIterator for &'a $name> { + type Item = $name<&'a T>; + type IntoIter = $iter_name>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + $iter_name((&self.0).into_iter()) + } + } + + impl<'a, T, const N: usize> IntoIterator for &'a mut $name<[T; N]> { + type Item = $name<&'a mut T>; + type IntoIter = $iter_name>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + $iter_name((&mut self.0).into_iter()) + } + } + + impl<'a, 'b, T> IntoIterator for &'a mut $name<&'b mut [T]> { + type Item = $name<&'a mut T>; + type IntoIter = $iter_name>; #[inline(always)] fn into_iter(self) -> Self::IntoIter { @@ -612,6 +692,28 @@ macro_rules! make_hues { } } + #[cfg(feature = "alloc")] + impl<'a, T> IntoIterator for &'a mut $name> { + type Item = $name<&'a mut T>; + type IntoIter = $iter_name>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + $iter_name((&mut self.0).into_iter()) + } + } + + #[cfg(feature = "alloc")] + impl<'a, T> IntoIterator for &'a mut $name> { + type Item = $name<&'a mut T>; + type IntoIter = $iter_name>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + $iter_name((&mut *self.0).into_iter()) + } + } + #[doc = concat!("Iterator over [`", stringify!($name), "`] values.")] pub struct $iter_name(I); diff --git a/palette/src/hwb.rs b/palette/src/hwb.rs index 1e7d8df14..7b84540be 100644 --- a/palette/src/hwb.rs +++ b/palette/src/hwb.rs @@ -366,9 +366,6 @@ unsafe impl bytemuck::Pod for Hwb where T: bytemuck::Pod {} mod test { use super::Hwb; - #[cfg(feature = "alloc")] - use crate::Srgb; - test_convert_into_from_xyz!(Hwb); #[cfg(feature = "approx")] @@ -456,24 +453,12 @@ mod test { } struct_of_arrays_tests!( - Hwb, - Hwb::new(0.1f32, 0.2, 0.3), - Hwb::new(0.2, 0.3, 0.4), - Hwb::new(0.3, 0.4, 0.5) + Hwb[hue, whiteness, blackness] phantom: standard, + super::Hwba::new(0.1f32, 0.2, 0.3, 0.4), + super::Hwba::new(0.2, 0.3, 0.4, 0.5), + super::Hwba::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{encoding::Srgb, hwb::Hwba}; - - struct_of_arrays_tests!( - Hwba, - Hwba::new(0.1f32, 0.2, 0.3, 0.4), - Hwba::new(0.2, 0.3, 0.4, 0.5), - Hwba::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/lab.rs b/palette/src/lab.rs index 961bab216..f81febf85 100644 --- a/palette/src/lab.rs +++ b/palette/src/lab.rs @@ -445,24 +445,12 @@ mod test { } struct_of_arrays_tests!( - Lab, - Lab::new(0.1f32, 0.2, 0.3), - Lab::new(0.2, 0.3, 0.4), - Lab::new(0.3, 0.4, 0.5) + Lab[l, a, b] phantom: white_point, + super::Laba::new(0.1f32, 0.2, 0.3, 0.4), + super::Laba::new(0.2, 0.3, 0.4, 0.5), + super::Laba::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{lab::Laba, white_point::D65}; - - struct_of_arrays_tests!( - Laba, - Laba::new(0.1f32, 0.2, 0.3, 0.4), - Laba::new(0.2, 0.3, 0.4, 0.5), - Laba::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/lch.rs b/palette/src/lch.rs index c0c18807f..98d341d8b 100644 --- a/palette/src/lch.rs +++ b/palette/src/lch.rs @@ -455,24 +455,12 @@ mod test { } struct_of_arrays_tests!( - Lch, - Lch::new(0.1f32, 0.2, 0.3), - Lch::new(0.2, 0.3, 0.4), - Lch::new(0.3, 0.4, 0.5) + Lch[l, chroma, hue] phantom: white_point, + super::Lcha::new(0.1f32, 0.2, 0.3, 0.4), + super::Lcha::new(0.2, 0.3, 0.4, 0.5), + super::Lcha::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{lch::Lcha, white_point::D65}; - - struct_of_arrays_tests!( - Lcha, - Lcha::new(0.1f32, 0.2, 0.3, 0.4), - Lcha::new(0.2, 0.3, 0.4, 0.5), - Lcha::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/lchuv.rs b/palette/src/lchuv.rs index bf55999bd..4a3882646 100644 --- a/palette/src/lchuv.rs +++ b/palette/src/lchuv.rs @@ -317,24 +317,12 @@ mod test { } struct_of_arrays_tests!( - Lchuv, - Lchuv::new(0.1f32, 0.2, 0.3), - Lchuv::new(0.2, 0.3, 0.4), - Lchuv::new(0.3, 0.4, 0.5) + Lchuv[l, chroma, hue] phantom: white_point, + super::Lchuva::new(0.1f32, 0.2, 0.3, 0.4), + super::Lchuva::new(0.2, 0.3, 0.4, 0.5), + super::Lchuva::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{lchuv::Lchuva, white_point::D65}; - - struct_of_arrays_tests!( - Lchuva, - Lchuva::new(0.1f32, 0.2, 0.3, 0.4), - Lchuva::new(0.2, 0.3, 0.4, 0.5), - Lchuva::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/luma/luma.rs b/palette/src/luma/luma.rs index d04e0fc72..5b0d704c2 100644 --- a/palette/src/luma/luma.rs +++ b/palette/src/luma/luma.rs @@ -895,24 +895,12 @@ mod test { } struct_of_arrays_tests!( - Luma, - Luma::new(0.1f32), - Luma::new(0.2), - Luma::new(0.3) + Luma[luma] phantom: standard, + super::Lumaa::new(0.1f32, 0.4), + super::Lumaa::new(0.2, 0.5), + super::Lumaa::new(0.3, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{encoding::Srgb, luma::Lumaa}; - - struct_of_arrays_tests!( - Lumaa, - Lumaa::new(0.1f32, 0.4), - Lumaa::new(0.2, 0.5), - Lumaa::new(0.3, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/luv.rs b/palette/src/luv.rs index 8f5722e32..ec39a18a5 100644 --- a/palette/src/luv.rs +++ b/palette/src/luv.rs @@ -386,24 +386,12 @@ mod test { } struct_of_arrays_tests!( - Luv, - Luv::new(0.1f32, 0.2, 0.3), - Luv::new(0.2, 0.3, 0.4), - Luv::new(0.3, 0.4, 0.5) + Luv[l, u, v] phantom: white_point, + super::Luva::new(0.1f32, 0.2, 0.3, 0.4), + super::Luva::new(0.2, 0.3, 0.4, 0.5), + super::Luva::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{luv::Luva, white_point::D65}; - - struct_of_arrays_tests!( - Luva, - Luva::new(0.1f32, 0.2, 0.3, 0.4), - Luva::new(0.2, 0.3, 0.4, 0.5), - Luva::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/macros/struct_of_arrays.rs b/palette/src/macros/struct_of_arrays.rs index 82200a617..937b5656e 100644 --- a/palette/src/macros/struct_of_arrays.rs +++ b/palette/src/macros/struct_of_arrays.rs @@ -46,222 +46,906 @@ macro_rules! impl_struct_of_array_traits { } } - impl<$($phantom_ty,)? C> IntoIterator for $self_ty<$($phantom_ty,)? C> + impl<$($phantom_ty,)? T, const N: usize> IntoIterator for $self_ty<$($phantom_ty,)? [T; N]> + { + type Item = $self_ty<$($phantom_ty,)? T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: IntoIterator::into_iter(self.$element),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<$($phantom_ty,)? T, const N: usize> IntoIterator for crate::alpha::Alpha<$self_ty<$($phantom_ty,)? [T; N]>, [T; N]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? T>, T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::array::IntoIter>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: self.color.into_iter(), + alpha: IntoIterator::into_iter(self.alpha) + } + } + } + + impl<'a, $($phantom_ty,)? T> IntoIterator for $self_ty<$($phantom_ty,)? &'a [T]> + { + type Item = $self_ty<$($phantom_ty,)? &'a T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: self.$element.into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, $($phantom_ty,)? T> IntoIterator for crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a [T]>, &'a [T]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: self.color.into_iter(), + alpha: self.alpha.into_iter(), + } + } + } + + impl<'a, $($phantom_ty,)? T> IntoIterator for $self_ty<$($phantom_ty,)? &'a mut [T]> + { + type Item = $self_ty<$($phantom_ty,)? &'a mut T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: self.$element.into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, $($phantom_ty,)? T> IntoIterator for crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut [T]>, &'a mut [T]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut T>, &'a mut T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::IterMut<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: self.color.into_iter(), + alpha: self.alpha.into_iter(), + } + } + } + + #[cfg(feature = "alloc")] + impl<$($phantom_ty,)? T> IntoIterator for $self_ty<$($phantom_ty,)? alloc::vec::Vec> + { + type Item = $self_ty<$($phantom_ty,)? T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: self.$element.into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, $($phantom_ty,)? T> IntoIterator for crate::alpha::Alpha<$self_ty<$($phantom_ty,)? alloc::vec::Vec>, alloc::vec::Vec> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? T>, T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, alloc::vec::IntoIter>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: self.color.into_iter(), + alpha: self.alpha.into_iter(), + } + } + } + + impl<'a, $($phantom_ty,)? T, const N: usize> IntoIterator for &'a $self_ty<$($phantom_ty,)? [T; N]> + { + type Item = $self_ty<$($phantom_ty,)? &'a T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: (&self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, $($phantom_ty,)? T, const N: usize> IntoIterator for &'a crate::alpha::Alpha<$self_ty<$($phantom_ty,)? [T; N]>, [T; N]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&self.color).into_iter(), + alpha: (&self.alpha).into_iter(), + } + } + } + + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a $self_ty<$($phantom_ty,)? &'b [T]> + { + type Item = $self_ty<$($phantom_ty,)? &'a T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: (&self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'b [T]>, &'b [T]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: self.color.into_iter(), + alpha: self.alpha.into_iter(), + } + } + } + + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a $self_ty<$($phantom_ty,)? &'b mut [T]> + { + type Item = $self_ty<$($phantom_ty,)? &'a T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: (&*self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'b mut [T]>, &'b mut [T]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&self.color).into_iter(), + alpha: (&*self.alpha).into_iter(), + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, $($phantom_ty,)? T> IntoIterator for &'a $self_ty<$($phantom_ty,)? alloc::vec::Vec> + { + type Item = $self_ty<$($phantom_ty,)? &'a T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: (&self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a crate::alpha::Alpha<$self_ty<$($phantom_ty,)? alloc::vec::Vec>, alloc::vec::Vec> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&self.color).into_iter(), + alpha: (&self.alpha).into_iter(), + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, $($phantom_ty,)? T> IntoIterator for &'a $self_ty<$($phantom_ty,)? alloc::boxed::Box<[T]>> + { + type Item = $self_ty<$($phantom_ty,)? &'a T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: (&self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a crate::alpha::Alpha<$self_ty<$($phantom_ty,)? alloc::boxed::Box<[T]>>, alloc::boxed::Box<[T]>> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&self.color).into_iter(), + alpha: (&self.alpha).into_iter(), + } + } + } + + impl<'a, $($phantom_ty,)? T, const N: usize> IntoIterator for &'a mut $self_ty<$($phantom_ty,)? [T; N]> + { + type Item = $self_ty<$($phantom_ty,)? &'a mut T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: (&mut self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, $($phantom_ty,)? T, const N: usize> IntoIterator for &'a mut crate::alpha::Alpha<$self_ty<$($phantom_ty,)? [T; N]>, [T; N]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut T>, &'a mut T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::IterMut<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&mut self.color).into_iter(), + alpha: (&mut self.alpha).into_iter(), + } + } + } + + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a mut $self_ty<$($phantom_ty,)? &'b mut [T]> + { + type Item = $self_ty<$($phantom_ty,)? &'a mut T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: self.$element.into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a mut crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'b mut [T]>, &'b mut [T]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut T>, &'a mut T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::IterMut<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&mut self.color).into_iter(), + alpha: (self.alpha).into_iter(), + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, $($phantom_ty,)? T> IntoIterator for &'a mut $self_ty<$($phantom_ty,)? alloc::vec::Vec> + { + type Item = $self_ty<$($phantom_ty,)? &'a mut T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: (&mut self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a mut crate::alpha::Alpha<$self_ty<$($phantom_ty,)? alloc::vec::Vec>, alloc::vec::Vec> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut T>, &'a mut T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::IterMut<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&mut self.color).into_iter(), + alpha: (&mut self.alpha).into_iter(), + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, $($phantom_ty,)? T> IntoIterator for &'a mut $self_ty<$($phantom_ty,)? alloc::boxed::Box<[T]>> + where + T: 'a + { + type Item = $self_ty<$($phantom_ty,)? &'a mut T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + $($element: (&mut *self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a mut crate::alpha::Alpha<$self_ty<$($phantom_ty,)? alloc::boxed::Box<[T]>>, alloc::boxed::Box<[T]>> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut T>, &'a mut T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::IterMut<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&mut self.color).into_iter(), + alpha: (&mut *self.alpha).into_iter(), + } + } + } + + #[doc = concat!("An iterator for [`", stringify!($self_ty), "`] values.")] + pub struct Iter { + $(pub(crate) $element: I,)+ + $(pub(crate) $phantom: core::marker::PhantomData<$phantom_ty>)? + } + + impl Iterator for Iter + where + I: Iterator, + { + type Item = $self_ty<$($phantom_ty,)? I::Item>; + + #[inline(always)] + fn next(&mut self) -> Option { + $(let $element = self.$element.next();)+ + + if let ($(Some($element),)+) = ($($element,)+) { + Some($self_ty { + $($element,)+ + $($phantom: core::marker::PhantomData,)? + }) + } else { + None + } + } + + #[inline(always)] + fn size_hint(&self) -> (usize, Option) { + let hint = first!($((self.$element)),+).size_hint(); + skip_first!($((debug_assert_eq!(self.$element.size_hint(), hint, "the component iterators have different size hints");)),+); + + hint + } + + #[inline(always)] + fn count(self) -> usize { + let count = first!($((self.$element)),+).count(); + skip_first!($((debug_assert_eq!(self.$element.count(), count, "the component iterators have different counts");)),+); + + count + } + } + + impl DoubleEndedIterator for Iter + where + I: DoubleEndedIterator, + { + #[inline(always)] + fn next_back(&mut self) -> Option { + $(let $element = self.$element.next_back();)+ + + if let ($(Some($element),)+) = ($($element,)+) { + Some($self_ty { + $($element,)+ + $($phantom: core::marker::PhantomData,)? + }) + } else { + None + } + } + } + + impl ExactSizeIterator for Iter + where + I: ExactSizeIterator, + { + #[inline(always)] + fn len(&self) -> usize { + let len = first!($((self.$element)),+).len(); + skip_first!($((debug_assert_eq!(self.$element.len(), len, "the component iterators have different lengths");)),+); + + len + } + } + } +} + +macro_rules! impl_struct_of_array_traits_hue { + ( $self_ty: ident, $hue_iter_ty: ident, [$($element: ident),+] $(, $phantom: ident)?) => { + impl_struct_of_array_traits_hue!($self_ty<>, $hue_iter_ty, [$($element),+] $(, $phantom)?); + }; + ( $self_ty: ident < $($phantom_ty: ident)? > , $hue_iter_ty: ident, [$($element: ident),+] $(, $phantom: ident)?) => { + impl<$($phantom_ty,)? T, C> Extend<$self_ty<$($phantom_ty,)? T>> for $self_ty<$($phantom_ty,)? C> + where + C: Extend, + { + #[inline(always)] + fn extend>>(&mut self, iter: I) { + let iter = iter.into_iter(); + + for color in iter { + self.hue.extend(core::iter::once(color.hue.into_inner())); + $(self.$element.extend(core::iter::once(color.$element));)+ + } + } + } + + impl<$($phantom_ty,)? T, C> core::iter::FromIterator<$self_ty<$($phantom_ty,)? T>> for $self_ty<$($phantom_ty,)? C> where - C: IntoIterator, + Self: Extend<$self_ty<$($phantom_ty,)? T>>, + C: Default, + { + #[inline(always)] + fn from_iter>>(iter: I) -> Self { + let mut result = Self { + hue: C::default().into(), + $($element: C::default(),)+ + $($phantom: core::marker::PhantomData)? + }; + result.extend(iter); + + result + } + } + + impl<$($phantom_ty,)? T, const N: usize> IntoIterator for $self_ty<$($phantom_ty,)? [T; N]> + { + type Item = $self_ty<$($phantom_ty,)? T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + hue: self.hue.into_iter(), + $($element: IntoIterator::into_iter(self.$element),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<$($phantom_ty,)? T, const N: usize> IntoIterator for crate::alpha::Alpha<$self_ty<$($phantom_ty,)? [T; N]>, [T; N]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? T>, T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::array::IntoIter>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: self.color.into_iter(), + alpha: IntoIterator::into_iter(self.alpha) + } + } + } + + impl<'a, $($phantom_ty,)? T> IntoIterator for $self_ty<$($phantom_ty,)? &'a [T]> { - type Item = $self_ty<$($phantom_ty,)? C::Item>; + type Item = $self_ty<$($phantom_ty,)? &'a T>; - type IntoIter = Iter; + type IntoIter = Iter $(,$phantom_ty)?>; #[inline(always)] fn into_iter(self) -> Self::IntoIter { Iter { + hue: self.hue.into_iter(), $($element: self.$element.into_iter(),)+ $($phantom: core::marker::PhantomData)? } } } - impl<'a, $($phantom_ty,)? C> IntoIterator for &'a $self_ty<$($phantom_ty,)? C> - where - &'a C: IntoIterator, + impl<'a, $($phantom_ty,)? T> IntoIterator for crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a [T]>, &'a [T]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: self.color.into_iter(), + alpha: self.alpha.into_iter(), + } + } + } + + impl<'a, $($phantom_ty,)? T> IntoIterator for $self_ty<$($phantom_ty,)? &'a mut [T]> + { + type Item = $self_ty<$($phantom_ty,)? &'a mut T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + hue: self.hue.into_iter(), + $($element: self.$element.into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, $($phantom_ty,)? T> IntoIterator for crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut [T]>, &'a mut [T]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut T>, &'a mut T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::IterMut<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: self.color.into_iter(), + alpha: self.alpha.into_iter(), + } + } + } + + #[cfg(feature = "alloc")] + impl<$($phantom_ty,)? T> IntoIterator for $self_ty<$($phantom_ty,)? alloc::vec::Vec> + { + type Item = $self_ty<$($phantom_ty,)? T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + hue: self.hue.into_iter(), + $($element: self.$element.into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, $($phantom_ty,)? T> IntoIterator for crate::alpha::Alpha<$self_ty<$($phantom_ty,)? alloc::vec::Vec>, alloc::vec::Vec> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? T>, T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, alloc::vec::IntoIter>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: self.color.into_iter(), + alpha: self.alpha.into_iter(), + } + } + } + + impl<'a, $($phantom_ty,)? T, const N: usize> IntoIterator for &'a $self_ty<$($phantom_ty,)? [T; N]> + { + type Item = $self_ty<$($phantom_ty,)? &'a T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + hue: (&self.hue).into_iter(), + $($element: (&self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, $($phantom_ty,)? T, const N: usize> IntoIterator for &'a crate::alpha::Alpha<$self_ty<$($phantom_ty,)? [T; N]>, [T; N]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&self.color).into_iter(), + alpha: (&self.alpha).into_iter(), + } + } + } + + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a $self_ty<$($phantom_ty,)? &'b [T]> + { + type Item = $self_ty<$($phantom_ty,)? &'a T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + hue: self.hue.into_iter(), + $($element: (&self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'b [T]>, &'b [T]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: self.color.into_iter(), + alpha: self.alpha.into_iter(), + } + } + } + + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a $self_ty<$($phantom_ty,)? &'b mut [T]> + { + type Item = $self_ty<$($phantom_ty,)? &'a T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + hue: (&self.hue).into_iter(), + $($element: (&*self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'b mut [T]>, &'b mut [T]> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&self.color).into_iter(), + alpha: (&*self.alpha).into_iter(), + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, $($phantom_ty,)? T> IntoIterator for &'a $self_ty<$($phantom_ty,)? alloc::vec::Vec> + { + type Item = $self_ty<$($phantom_ty,)? &'a T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + + #[inline(always)] + fn into_iter(self) -> Self::IntoIter { + Iter { + hue: (&self.hue).into_iter(), + $($element: (&self.$element).into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a crate::alpha::Alpha<$self_ty<$($phantom_ty,)? alloc::vec::Vec>, alloc::vec::Vec> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&self.color).into_iter(), + alpha: (&self.alpha).into_iter(), + } + } + } + + #[cfg(feature = "alloc")] + impl<'a, $($phantom_ty,)? T> IntoIterator for &'a $self_ty<$($phantom_ty,)? alloc::boxed::Box<[T]>> { - type Item = $self_ty<$($phantom_ty,)? <&'a C as IntoIterator>::Item>; + type Item = $self_ty<$($phantom_ty,)? &'a T>; - type IntoIter = Iter<<&'a C as IntoIterator>::IntoIter $(,$phantom_ty)?>; + type IntoIter = Iter $(,$phantom_ty)?>; #[inline(always)] fn into_iter(self) -> Self::IntoIter { Iter { + hue: (&self.hue).into_iter(), $($element: (&self.$element).into_iter(),)+ $($phantom: core::marker::PhantomData)? } } } - impl<'a, $($phantom_ty,)? C> IntoIterator for &'a mut $self_ty<$($phantom_ty,)? C> - where - &'a mut C: IntoIterator, + #[cfg(feature = "alloc")] + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a crate::alpha::Alpha<$self_ty<$($phantom_ty,)? alloc::boxed::Box<[T]>>, alloc::boxed::Box<[T]>> + { + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a T>, &'a T>; + + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::Iter<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&self.color).into_iter(), + alpha: (&self.alpha).into_iter(), + } + } + } + + impl<'a, $($phantom_ty,)? T, const N: usize> IntoIterator for &'a mut $self_ty<$($phantom_ty,)? [T; N]> { - type Item = $self_ty<$($phantom_ty,)? <&'a mut C as IntoIterator>::Item>; + type Item = $self_ty<$($phantom_ty,)? &'a mut T>; - type IntoIter = Iter<<&'a mut C as IntoIterator>::IntoIter $(,$phantom_ty)?>; + type IntoIter = Iter $(,$phantom_ty)?>; #[inline(always)] fn into_iter(self) -> Self::IntoIter { Iter { + hue: (&mut self.hue).into_iter(), $($element: (&mut self.$element).into_iter(),)+ $($phantom: core::marker::PhantomData)? } } } - #[doc = concat!("An iterator for [`", stringify!($self_ty), "`] values.")] - pub struct Iter { - $(pub(crate) $element: I,)+ - $(pub(crate) $phantom: core::marker::PhantomData<$phantom_ty>)? - } - - impl Iterator for Iter - where - I: Iterator, + impl<'a, $($phantom_ty,)? T, const N: usize> IntoIterator for &'a mut crate::alpha::Alpha<$self_ty<$($phantom_ty,)? [T; N]>, [T; N]> { - type Item = $self_ty<$($phantom_ty,)? I::Item>; + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut T>, &'a mut T>; - #[inline(always)] - fn next(&mut self) -> Option { - $(let $element = self.$element.next();)+ + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::IterMut<'a, T>>; - if let ($(Some($element),)+) = ($($element,)+) { - Some($self_ty { - $($element,)+ - $($phantom: core::marker::PhantomData,)? - }) - } else { - None + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&mut self.color).into_iter(), + alpha: (&mut self.alpha).into_iter(), } } - - #[inline(always)] - fn size_hint(&self) -> (usize, Option) { - let hint = first!($((self.$element)),+).size_hint(); - skip_first!($((debug_assert_eq!(self.$element.size_hint(), hint, "the component iterators have different size hints");)),+); - - hint - } - - #[inline(always)] - fn count(self) -> usize { - let count = first!($((self.$element)),+).count(); - skip_first!($((debug_assert_eq!(self.$element.count(), count, "the component iterators have different counts");)),+); - - count - } } - impl DoubleEndedIterator for Iter - where - I: DoubleEndedIterator, + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a mut $self_ty<$($phantom_ty,)? &'b mut [T]> { - #[inline(always)] - fn next_back(&mut self) -> Option { - $(let $element = self.$element.next_back();)+ + type Item = $self_ty<$($phantom_ty,)? &'a mut T>; - if let ($(Some($element),)+) = ($($element,)+) { - Some($self_ty { - $($element,)+ - $($phantom: core::marker::PhantomData,)? - }) - } else { - None - } - } - } + type IntoIter = Iter $(,$phantom_ty)?>; - impl ExactSizeIterator for Iter - where - I: ExactSizeIterator, - { #[inline(always)] - fn len(&self) -> usize { - let len = first!($((self.$element)),+).len(); - skip_first!($((debug_assert_eq!(self.$element.len(), len, "the component iterators have different lengths");)),+); - - len + fn into_iter(self) -> Self::IntoIter { + Iter { + hue: (&mut self.hue).into_iter(), + $($element: self.$element.into_iter(),)+ + $($phantom: core::marker::PhantomData)? + } } } - } -} -macro_rules! impl_struct_of_array_traits_hue { - ( $self_ty: ident, $hue_iter_ty: ident, [$($element: ident),+] $(, $phantom: ident)?) => { - impl_struct_of_array_traits_hue!($self_ty<>, $hue_iter_ty, [$($element),+] $(, $phantom)?); - }; - ( $self_ty: ident < $($phantom_ty: ident)? > , $hue_iter_ty: ident, [$($element: ident),+] $(, $phantom: ident)?) => { - impl<$($phantom_ty,)? T, C> Extend<$self_ty<$($phantom_ty,)? T>> for $self_ty<$($phantom_ty,)? C> - where - C: Extend, + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a mut crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'b mut [T]>, &'b mut [T]> { - #[inline(always)] - fn extend>>(&mut self, iter: I) { - let iter = iter.into_iter(); + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut T>, &'a mut T>; - for color in iter { - self.hue.extend(core::iter::once(color.hue.into_inner())); - $(self.$element.extend(core::iter::once(color.$element));)+ + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::IterMut<'a, T>>; + + fn into_iter(self) -> Self::IntoIter { + crate::alpha::Iter { + color: (&mut self.color).into_iter(), + alpha: (self.alpha).into_iter(), } } } - impl<$($phantom_ty,)? T, C> core::iter::FromIterator<$self_ty<$($phantom_ty,)? T>> for $self_ty<$($phantom_ty,)? C> - where - Self: Extend<$self_ty<$($phantom_ty,)? T>>, - C: Default, + #[cfg(feature = "alloc")] + impl<'a, $($phantom_ty,)? T> IntoIterator for &'a mut $self_ty<$($phantom_ty,)? alloc::vec::Vec> { + type Item = $self_ty<$($phantom_ty,)? &'a mut T>; + + type IntoIter = Iter $(,$phantom_ty)?>; + #[inline(always)] - fn from_iter>>(iter: I) -> Self { - let mut result = Self { - hue: C::default().into(), - $($element: C::default(),)+ + fn into_iter(self) -> Self::IntoIter { + Iter { + hue: (&mut self.hue).into_iter(), + $($element: (&mut self.$element).into_iter(),)+ $($phantom: core::marker::PhantomData)? - }; - result.extend(iter); - - result + } } } - impl<$($phantom_ty,)? C> IntoIterator for $self_ty<$($phantom_ty,)? C> - where - C: IntoIterator, + #[cfg(feature = "alloc")] + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a mut crate::alpha::Alpha<$self_ty<$($phantom_ty,)? alloc::vec::Vec>, alloc::vec::Vec> { - type Item = $self_ty<$($phantom_ty,)? C::Item>; + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut T>, &'a mut T>; - type IntoIter = Iter; + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::IterMut<'a, T>>; - #[inline(always)] fn into_iter(self) -> Self::IntoIter { - Iter { - hue: self.hue.into_iter(), - $($element: self.$element.into_iter(),)+ - $($phantom: core::marker::PhantomData)? + crate::alpha::Iter { + color: (&mut self.color).into_iter(), + alpha: (&mut self.alpha).into_iter(), } } } - impl<'a, $($phantom_ty,)? C> IntoIterator for &'a $self_ty<$($phantom_ty,)? C> - where - &'a C: IntoIterator + 'a, + #[cfg(feature = "alloc")] + impl<'a, $($phantom_ty,)? T> IntoIterator for &'a mut $self_ty<$($phantom_ty,)? alloc::boxed::Box<[T]>> { - type Item = $self_ty<$($phantom_ty,)? <&'a C as IntoIterator>::Item>; + type Item = $self_ty<$($phantom_ty,)? &'a mut T>; - type IntoIter = Iter<<&'a C as IntoIterator>::IntoIter $(,$phantom_ty)?>; + type IntoIter = Iter $(,$phantom_ty)?>; #[inline(always)] fn into_iter(self) -> Self::IntoIter { Iter { - hue: (&self.hue).into_iter(), - $($element: (&self.$element).into_iter(),)+ + hue: (&mut self.hue).into_iter(), + $($element: (&mut *self.$element).into_iter(),)+ $($phantom: core::marker::PhantomData)? } } } - impl<'a, $($phantom_ty,)? C> IntoIterator for &'a mut $self_ty<$($phantom_ty,)? C> - where - &'a mut C: IntoIterator + 'a, + #[cfg(feature = "alloc")] + impl<'a, 'b, $($phantom_ty,)? T> IntoIterator for &'a mut crate::alpha::Alpha<$self_ty<$($phantom_ty,)? alloc::boxed::Box<[T]>>, alloc::boxed::Box<[T]>> { - type Item = $self_ty<$($phantom_ty,)? <&'a mut C as IntoIterator>::Item>; + type Item = crate::alpha::Alpha<$self_ty<$($phantom_ty,)? &'a mut T>, &'a mut T>; - type IntoIter = Iter<<&'a mut C as IntoIterator>::IntoIter $(,$phantom_ty)?>; + type IntoIter = crate::alpha::Iter $(,$phantom_ty)?>, core::slice::IterMut<'a, T>>; - #[inline(always)] fn into_iter(self) -> Self::IntoIter { - Iter { - hue: (&mut self.hue).into_iter(), - $($element: (&mut self.$element).into_iter(),)+ - $($phantom: core::marker::PhantomData)? + crate::alpha::Iter { + color: (&mut self.color).into_iter(), + alpha: (&mut *self.alpha).into_iter(), } } } @@ -757,23 +1441,48 @@ macro_rules! impl_struct_of_arrays_methods_hue { #[cfg(test)] macro_rules! struct_of_arrays_tests { - ($color_ty: ident $(<$phantom_ty:ident>)?, $($values:expr),+) => { + ($color_ty: ident $(<$phantom_ty:ty>)? [$($element: ident),+] $(phantom: $phantom: ident)?, $($values:expr),+) => { #[cfg(feature = "alloc")] #[test] fn collect() { - let vec_of_colors = vec![$($values),+]; + let vec_of_colors = vec![$($values.color),+]; let color_of_vecs: $color_ty<$($phantom_ty,)? Vec<_>> = vec_of_colors.into_iter().collect(); let vec_of_colors: Vec<_> = color_of_vecs.into_iter().collect(); + assert_eq!(vec_of_colors, vec![$($values.color),+]); + } + + #[cfg(feature = "alloc")] + #[test] + fn collect_alpha() { + let vec_of_colors = vec![$($values),+]; + let color_of_vecs: crate::alpha::Alpha<$color_ty<$($phantom_ty,)? Vec<_>>, Vec<_>> = vec_of_colors.into_iter().collect(); + let vec_of_colors: Vec<_> = color_of_vecs.into_iter().collect(); + assert_eq!(vec_of_colors, vec![$($values),+]); } + #[cfg(feature = "alloc")] #[test] fn extend() { + let vec_of_colors = vec![$($values.color),+]; + + let mut color_of_vecs = $color_ty::<$($phantom_ty,)? Vec<_>>::with_capacity(vec_of_colors.len()); + color_of_vecs.extend(vec_of_colors); + + let vec_of_colors: Vec<_> = color_of_vecs.into_iter().collect(); + + assert_eq!(vec_of_colors, vec![$($values.color),+]); + } + + + #[cfg(feature = "alloc")] + #[test] + fn extend_alpha() { let vec_of_colors = vec![$($values),+]; - let mut color_of_vecs: $color_ty<$($phantom_ty,)? Vec<_>> = $color_ty::with_capacity(vec_of_colors.len()); + let mut color_of_vecs = crate::alpha::Alpha::<$color_ty<$($phantom_ty,)? Vec<_>>, Vec<_>>::with_capacity(vec_of_colors.len()); color_of_vecs.extend(vec_of_colors); let vec_of_colors: Vec<_> = color_of_vecs.into_iter().collect(); @@ -781,10 +1490,11 @@ macro_rules! struct_of_arrays_tests { assert_eq!(vec_of_colors, vec![$($values),+]); } + #[cfg(feature = "alloc")] #[test] fn pop_push() { - let vec_of_colors = vec![$($values),+]; + let vec_of_colors = vec![$($values.color),+]; let mut color_of_vecs: $color_ty<$($phantom_ty,)? Vec<_>> = vec_of_colors.into_iter().collect(); let last = color_of_vecs.pop().unwrap(); @@ -792,13 +1502,28 @@ macro_rules! struct_of_arrays_tests { let vec_of_colors: Vec<_> = color_of_vecs.into_iter().collect(); + assert_eq!(vec_of_colors, vec![$($values.color),+]); + } + + + #[cfg(feature = "alloc")] + #[test] + fn pop_push_alpha() { + let vec_of_colors = vec![$($values),+]; + + let mut color_of_vecs: crate::alpha::Alpha<$color_ty<$($phantom_ty,)? Vec<_>>, Vec<_>> = vec_of_colors.into_iter().collect(); + let last = color_of_vecs.pop().unwrap(); + color_of_vecs.push(last); + + let vec_of_colors: Vec<_> = color_of_vecs.into_iter().collect(); + assert_eq!(vec_of_colors, vec![$($values),+]); } #[cfg(feature = "alloc")] #[test] fn clear() { - let vec_of_colors = vec![$($values),+]; + let vec_of_colors = vec![$($values.color),+]; let mut color_of_vecs: $color_ty<$($phantom_ty,)? Vec<_>> = vec_of_colors.into_iter().collect(); color_of_vecs.clear(); @@ -810,14 +1535,43 @@ macro_rules! struct_of_arrays_tests { #[cfg(feature = "alloc")] #[test] - fn drain() { + fn clear_alpha() { let vec_of_colors = vec![$($values),+]; + let mut color_of_vecs: crate::alpha::Alpha<$color_ty<$($phantom_ty,)? Vec<_>>, Vec<_>> = vec_of_colors.into_iter().collect(); + color_of_vecs.clear(); + + let vec_of_colors: Vec<_> = color_of_vecs.into_iter().collect(); + + assert_eq!(vec_of_colors, vec![]); + } + + + #[cfg(feature = "alloc")] + #[test] + fn drain() { + let vec_of_colors = vec![$($values.color),+]; + let mut color_of_vecs: $color_ty<$($phantom_ty,)? Vec<_>> = vec_of_colors.into_iter().collect(); let vec_of_colors1: Vec<_> = color_of_vecs.drain(..).collect(); let vec_of_colors2: Vec<_> = color_of_vecs.into_iter().collect(); + assert_eq!(vec_of_colors1, vec![$($values.color),+]); + assert_eq!(vec_of_colors2, vec![]); + } + + + #[cfg(feature = "alloc")] + #[test] + fn drain_alpha() { + let vec_of_colors = vec![$($values),+]; + + let mut color_of_vecs: crate::alpha::Alpha<$color_ty<$($phantom_ty,)? Vec<_>>, Vec<_>> = vec_of_colors.into_iter().collect(); + + let vec_of_colors1: Vec<_> = color_of_vecs.drain(..).collect(); + let vec_of_colors2: Vec<_> = color_of_vecs.into_iter().collect(); + assert_eq!(vec_of_colors1, vec![$($values),+]); assert_eq!(vec_of_colors2, vec![]); } @@ -825,7 +1579,7 @@ macro_rules! struct_of_arrays_tests { #[cfg(feature = "alloc")] #[test] fn modify() { - let vec_of_colors = vec![$($values),+]; + let vec_of_colors = vec![$($values.color),+]; let mut color_of_vecs: $color_ty<$($phantom_ty,)? Vec<_>> = vec_of_colors.into_iter().collect(); @@ -835,7 +1589,245 @@ macro_rules! struct_of_arrays_tests { let vec_of_colors: Vec<_> = color_of_vecs.into_iter().collect(); + assert_eq!(vec_of_colors, vec![$($values.color + 2.0),+]); + } + + #[cfg(feature = "alloc")] + #[test] + fn modify_alpha() { + let vec_of_colors = vec![$($values),+]; + + let mut color_of_vecs: crate::alpha::Alpha<$color_ty<$($phantom_ty,)? Vec<_>>, Vec<_>> = vec_of_colors.into_iter().collect(); + + for mut color in &mut color_of_vecs { + color.set(color.copied() + 2.0); + } + + let vec_of_colors: Vec<_> = color_of_vecs.into_iter().collect(); + assert_eq!(vec_of_colors, vec![$($values + 2.0),+]); } + + #[test] + fn into_iterator() { + fn expect_move(_: impl Iterator>){} + fn expect_ref<'a>(_: impl Iterator>){} + fn expect_ref_mut<'a>(_: impl Iterator>){} + + let arrays = $color_ty::<$($phantom_ty,)? [f32; 0]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }; + let slices = $color_ty::<$($phantom_ty,)? &[f32]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }; + let mut_slices = $color_ty::<$($phantom_ty,)? &mut [f32]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }; + + expect_move(arrays.into_iter()); + expect_ref(slices.into_iter()); + expect_ref_mut(mut_slices.into_iter()); + } + + #[test] + fn into_iterator_alpha() { + use crate::alpha::Alpha; + + fn expect_move(_: impl Iterator, f32>>){} + fn expect_ref<'a>(_: impl Iterator, &'a f32>>){} + fn expect_ref_mut<'a>(_: impl Iterator, &'a mut f32>>){} + + let arrays = Alpha::<_, [f32; 0]>{ + color: $color_ty::<$($phantom_ty,)? [f32; 0]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }, + alpha: Default::default(), + }; + let slices = Alpha::<_, &[f32]>{ + color: $color_ty::<$($phantom_ty,)? &[f32]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }, + alpha: Default::default(), + }; + let mut_slices = Alpha::<_, &mut [f32]>{ + color: $color_ty::<$($phantom_ty,)? &mut [f32]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }, + alpha: Default::default(), + }; + + expect_move(arrays.into_iter()); + expect_ref(slices.into_iter()); + expect_ref_mut(mut_slices.into_iter()); + } + + #[test] + fn into_iterator_ref() { + fn expect_ref<'a>(_: impl Iterator>){} + fn expect_ref_mut<'a>(_: impl Iterator>){} + + let mut arrays = $color_ty::<$($phantom_ty,)? [f32; 0]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }; + let mut slices = $color_ty::<$($phantom_ty,)? &[f32]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }; + let mut mut_slices = $color_ty::<$($phantom_ty,)? &mut [f32]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }; + + expect_ref((&arrays).into_iter()); + expect_ref((&slices).into_iter()); + expect_ref((&mut_slices).into_iter()); + + expect_ref_mut((&mut arrays).into_iter()); + expect_ref((&mut slices).into_iter()); + expect_ref_mut((&mut mut_slices).into_iter()); + } + + #[test] + fn into_iterator_ref_alpha() { + use crate::alpha::Alpha; + + fn expect_ref<'a>(_: impl Iterator, &'a f32>>){} + fn expect_ref_mut<'a>(_: impl Iterator, &'a mut f32>>){} + + let mut arrays = Alpha::<_, [f32; 0]>{ + color: $color_ty::<$($phantom_ty,)? [f32; 0]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }, + alpha: Default::default(), + }; + let mut slices = Alpha::<_, &[f32]>{ + color: $color_ty::<$($phantom_ty,)? &[f32]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }, + alpha: Default::default(), + }; + let mut mut_slices = Alpha::<_, &mut [f32]>{ + color: $color_ty::<$($phantom_ty,)? &mut [f32]>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }, + alpha: Default::default(), + }; + + expect_ref((&arrays).into_iter()); + expect_ref((&slices).into_iter()); + expect_ref((&mut_slices).into_iter()); + + expect_ref_mut((&mut arrays).into_iter()); + expect_ref((&mut slices).into_iter()); + expect_ref_mut((&mut mut_slices).into_iter()); + } + + #[cfg(feature = "alloc")] + #[test] + fn into_iterator_alloc() { + fn expect_move(_: impl Iterator>){} + fn expect_ref<'a>(_: impl Iterator>){} + + let vecs = $color_ty::<$($phantom_ty,)? Vec>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }; + let boxed_slices = $color_ty::<$($phantom_ty,)? Box<[f32]>>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }; + + expect_move(vecs.into_iter()); + expect_ref(boxed_slices.into_iter()); + } + + #[cfg(feature = "alloc")] + #[test] + fn into_iterator_alloc_alpha() { + use crate::alpha::Alpha; + + fn expect_move(_: impl Iterator, f32>>){} + fn expect_ref<'a>(_: impl Iterator, &'a f32>>){} + + let vecs = Alpha::<_, Vec>{ + color: $color_ty::<$($phantom_ty,)? Vec>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }, + alpha: Default::default(), + }; + let boxed_slices = Alpha::<_, Box<[f32]>>{ + color: $color_ty::<$($phantom_ty,)? Box<[f32]>>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }, + alpha: Default::default(), + }; + + expect_move(vecs.into_iter()); + expect_ref(boxed_slices.into_iter()); + } + + #[cfg(feature = "alloc")] + #[test] + fn into_iterator_alloc_ref() { + fn expect_ref<'a>(_: impl Iterator>){} + fn expect_ref_mut<'a>(_: impl Iterator>){} + + let mut vecs = $color_ty::<$($phantom_ty,)? Vec>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }; + let mut boxed_slices = $color_ty::<$($phantom_ty,)? Box<[f32]>>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }; + + expect_ref((&vecs).into_iter()); + expect_ref((&boxed_slices).into_iter()); + + expect_ref_mut((&mut vecs).into_iter()); + expect_ref_mut((&mut boxed_slices).into_iter()); + } + + #[cfg(feature = "alloc")] + #[test] + fn into_iterator_alloc_ref_alpha() { + use crate::alpha::Alpha; + + fn expect_ref<'a>(_: impl Iterator, &'a f32>>){} + fn expect_ref_mut<'a>(_: impl Iterator, &'a mut f32>>){} + + let mut vecs = Alpha::<_, Vec>{ + color: $color_ty::<$($phantom_ty,)? Vec>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }, + alpha: Default::default(), + }; + let mut boxed_slices = Alpha::<_, Box<[f32]>>{ + color: $color_ty::<$($phantom_ty,)? Box<[f32]>>{ + $($element: Default::default(),)+ + $($phantom: core::marker::PhantomData,)? + }, + alpha: Default::default(), + }; + + expect_ref((&vecs).into_iter()); + expect_ref((&boxed_slices).into_iter()); + + expect_ref_mut((&mut vecs).into_iter()); + expect_ref_mut((&mut boxed_slices).into_iter()); + } } } diff --git a/palette/src/okhsl.rs b/palette/src/okhsl.rs index b5f60ebc8..9ebb692d8 100644 --- a/palette/src/okhsl.rs +++ b/palette/src/okhsl.rs @@ -429,21 +429,9 @@ mod tests { } struct_of_arrays_tests!( - Okhsl, - Okhsl::new(0.1f32, 0.2, 0.3), - Okhsl::new(0.2, 0.3, 0.4), - Okhsl::new(0.3, 0.4, 0.5) + Okhsl[hue, saturation, lightness], + super::Okhsla::new(0.1f32, 0.2, 0.3, 0.4), + super::Okhsla::new(0.2, 0.3, 0.4, 0.5), + super::Okhsla::new(0.3, 0.4, 0.5, 0.6) ); - - mod alpha { - #[cfg(feature = "alloc")] - use crate::okhsl::Okhsla; - - struct_of_arrays_tests!( - Okhsla, - Okhsla::new(0.1f32, 0.2, 0.3, 0.4), - Okhsla::new(0.2, 0.3, 0.4, 0.5), - Okhsla::new(0.3, 0.4, 0.5, 0.6) - ); - } } diff --git a/palette/src/okhsv.rs b/palette/src/okhsv.rs index 468416bdd..8a2166b7b 100644 --- a/palette/src/okhsv.rs +++ b/palette/src/okhsv.rs @@ -553,21 +553,9 @@ mod tests { } struct_of_arrays_tests!( - Okhsv, - Okhsv::new(0.1f32, 0.2, 0.3), - Okhsv::new(0.2, 0.3, 0.4), - Okhsv::new(0.3, 0.4, 0.5) + Okhsv[hue, saturation, value], + super::Okhsva::new(0.1f32, 0.2, 0.3, 0.4), + super::Okhsva::new(0.2, 0.3, 0.4, 0.5), + super::Okhsva::new(0.3, 0.4, 0.5, 0.6) ); - - mod alpha { - #[cfg(feature = "alloc")] - use crate::okhsv::Okhsva; - - struct_of_arrays_tests!( - Okhsva, - Okhsva::new(0.1f32, 0.2, 0.3, 0.4), - Okhsva::new(0.2, 0.3, 0.4, 0.5), - Okhsva::new(0.3, 0.4, 0.5, 0.6) - ); - } } diff --git a/palette/src/okhwb.rs b/palette/src/okhwb.rs index 0b9f3aa1c..93e9d8674 100644 --- a/palette/src/okhwb.rs +++ b/palette/src/okhwb.rs @@ -282,21 +282,9 @@ mod tests { } struct_of_arrays_tests!( - Okhwb, - Okhwb::new(0.1f32, 0.2, 0.3), - Okhwb::new(0.2, 0.3, 0.4), - Okhwb::new(0.3, 0.4, 0.5) + Okhwb[hue, whiteness, blackness], + super::Okhwba::new(0.1f32, 0.2, 0.3, 0.4), + super::Okhwba::new(0.2, 0.3, 0.4, 0.5), + super::Okhwba::new(0.3, 0.4, 0.5, 0.6) ); - - mod alpha { - #[cfg(feature = "alloc")] - use crate::okhwb::Okhwba; - - struct_of_arrays_tests!( - Okhwba, - Okhwba::new(0.1f32, 0.2, 0.3, 0.4), - Okhwba::new(0.2, 0.3, 0.4, 0.5), - Okhwba::new(0.3, 0.4, 0.5, 0.6) - ); - } } diff --git a/palette/src/oklab.rs b/palette/src/oklab.rs index e63948f08..51db0f31e 100644 --- a/palette/src/oklab.rs +++ b/palette/src/oklab.rs @@ -679,24 +679,12 @@ mod test { } struct_of_arrays_tests!( - Oklab, - Oklab::new(0.1f32, 0.2, 0.3), - Oklab::new(0.2, 0.3, 0.4), - Oklab::new(0.3, 0.4, 0.5) + Oklab[l, a, b], + super::Oklaba::new(0.1f32, 0.2, 0.3, 0.4), + super::Oklaba::new(0.2, 0.3, 0.4, 0.5), + super::Oklaba::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::oklab::Oklaba; - - struct_of_arrays_tests!( - Oklaba, - Oklaba::new(0.1f32, 0.2, 0.3, 0.4), - Oklaba::new(0.2, 0.3, 0.4, 0.5), - Oklaba::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/oklch.rs b/palette/src/oklch.rs index 69b696a06..49198bb9f 100644 --- a/palette/src/oklch.rs +++ b/palette/src/oklch.rs @@ -271,24 +271,12 @@ mod test { } struct_of_arrays_tests!( - Oklch, - Oklch::new(0.1f32, 0.2, 0.3), - Oklch::new(0.2, 0.3, 0.4), - Oklch::new(0.3, 0.4, 0.5) + Oklch[l, chroma, hue], + super::Oklcha::new(0.1f32, 0.2, 0.3, 0.4), + super::Oklcha::new(0.2, 0.3, 0.4, 0.5), + super::Oklcha::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::oklch::Oklcha; - - struct_of_arrays_tests!( - Oklcha, - Oklcha::new(0.1f32, 0.2, 0.3, 0.4), - Oklcha::new(0.2, 0.3, 0.4, 0.5), - Oklcha::new(0.3, 0.4, 0.5, 0.6) - ); - } - test_uniform_distribution! { Oklch as crate::Oklab { l: (0.0, 1.0), diff --git a/palette/src/rgb/rgb.rs b/palette/src/rgb/rgb.rs index fffe63e69..4d41acb7f 100644 --- a/palette/src/rgb/rgb.rs +++ b/palette/src/rgb/rgb.rs @@ -1498,24 +1498,12 @@ mod test { } struct_of_arrays_tests!( - Rgb, - Rgb::new(0.1f32, 0.2, 0.3), - Rgb::new(0.2, 0.3, 0.4), - Rgb::new(0.3, 0.4, 0.5) + Rgb[red, green, blue] phantom: standard, + Rgba::new(0.1f32, 0.2, 0.3, 0.4), + Rgba::new(0.2, 0.3, 0.4, 0.5), + Rgba::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{encoding::Srgb, rgb::Rgba}; - - struct_of_arrays_tests!( - Rgba, - Rgba::new(0.1f32, 0.2, 0.3, 0.4), - Rgba::new(0.2, 0.3, 0.4, 0.5), - Rgba::new(0.3, 0.4, 0.5, 0.6) - ); - } - test_uniform_distribution! { Rgb { red: (0.0, 1.0), diff --git a/palette/src/xyz.rs b/palette/src/xyz.rs index f69556542..07f9c4c3d 100644 --- a/palette/src/xyz.rs +++ b/palette/src/xyz.rs @@ -493,24 +493,12 @@ mod test { } struct_of_arrays_tests!( - Xyz, - Xyz::new(0.1f32, 0.2, 0.3), - Xyz::new(0.2, 0.3, 0.4), - Xyz::new(0.3, 0.4, 0.5) + Xyz[x, y, z] phantom: white_point, + super::Xyza::new(0.1f32, 0.2, 0.3, 0.4), + super::Xyza::new(0.2, 0.3, 0.4, 0.5), + super::Xyza::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{white_point::D65, xyz::Xyza}; - - struct_of_arrays_tests!( - Xyza, - Xyza::new(0.1f32, 0.2, 0.3, 0.4), - Xyza::new(0.2, 0.3, 0.4, 0.5), - Xyza::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette/src/yxy.rs b/palette/src/yxy.rs index 515ac64bb..4727ddbe2 100644 --- a/palette/src/yxy.rs +++ b/palette/src/yxy.rs @@ -362,24 +362,12 @@ mod test { } struct_of_arrays_tests!( - Yxy, - Yxy::new(0.1f32, 0.2, 0.3), - Yxy::new(0.2, 0.3, 0.4), - Yxy::new(0.3, 0.4, 0.5) + Yxy[x, y, luma] phantom: white_point, + super::Yxya::new(0.1f32, 0.2, 0.3, 0.4), + super::Yxya::new(0.2, 0.3, 0.4, 0.5), + super::Yxya::new(0.3, 0.4, 0.5, 0.6) ); - mod alpha { - #[cfg(feature = "alloc")] - use crate::{white_point::D65, yxy::Yxya}; - - struct_of_arrays_tests!( - Yxya, - Yxya::new(0.1f32, 0.2, 0.3, 0.4), - Yxya::new(0.2, 0.3, 0.4, 0.5), - Yxya::new(0.3, 0.4, 0.5, 0.6) - ); - } - #[cfg(feature = "serializing")] #[test] fn serialize() { diff --git a/palette_derive/src/meta/mod.rs b/palette_derive/src/meta/mod.rs index ab01c9b00..9f0fcc11c 100644 --- a/palette_derive/src/meta/mod.rs +++ b/palette_derive/src/meta/mod.rs @@ -207,21 +207,6 @@ impl ::quote::ToTokens for IdentOrIndex { } } -pub trait MetaParser: Default { - fn internal(&mut self); - fn parse_attribute(&mut self, attribute_name: Ident, attribute_tts: TokenStream) -> Result<()>; -} - -pub trait DataMetaParser: Default { - fn parse_struct_field_attribute( - &mut self, - field_name: IdentOrIndex, - ty: Type, - attribute_name: Ident, - attribute_tts: TokenStream, - ) -> Result<()>; -} - pub trait AttributeArgumentParser: Default { fn argument(&mut self, argument: Meta) -> Result<()>; }