macro_rules! impl_color_add { ($self_ty: ident , [$($element: ident),+]) => { impl_color_add!($self_ty<>, [$($element),+]); }; ($self_ty: ident < $($ty_param: ident),* > , [$($element: ident),+] $(, $phantom: ident)?) => { impl<$($ty_param,)* T> core::ops::Add for $self_ty<$($ty_param,)* T> where T: core::ops::Add { type Output = Self; fn add(self, other: Self) -> Self::Output { $self_ty { $($element: self.$element + other.$element,)+ $($phantom: core::marker::PhantomData,)? } } } impl<$($ty_param,)* T> core::ops::Add for $self_ty<$($ty_param,)* T> where T: core::ops::Add + Clone { type Output = Self; fn add(self, c: T) -> Self::Output { $self_ty { $($element: self.$element + c.clone(),)+ $($phantom: core::marker::PhantomData,)? } } } impl<$($ty_param,)* T> core::ops::AddAssign for $self_ty<$($ty_param,)* T> where T: core::ops::AddAssign, { fn add_assign(&mut self, other: Self) { $( self.$element += other.$element; )+ } } impl<$($ty_param,)* T> core::ops::AddAssign for $self_ty<$($ty_param,)* T> where T: core::ops::AddAssign + Clone { fn add_assign(&mut self, c: T) { $( self.$element += c.clone(); )+ } } impl<$($ty_param,)* T> $crate::num::SaturatingAdd for $self_ty<$($ty_param,)* T> where T: $crate::num::SaturatingAdd { type Output = Self; fn saturating_add(self, other: Self) -> Self::Output { $self_ty { $($element: self.$element.saturating_add(other.$element),)+ $($phantom: core::marker::PhantomData,)? } } } impl<$($ty_param,)* T> $crate::num::SaturatingAdd for $self_ty<$($ty_param,)* T> where T: $crate::num::SaturatingAdd + Clone { type Output = Self; fn saturating_add(self, c: T) -> Self::Output { $self_ty { $($element: self.$element.saturating_add(c.clone()),)+ $($phantom: core::marker::PhantomData,)? } } } }; } /// Implement `Sub` and `SubAssign` traits for a color space. /// /// Both scalars and color arithmetic are implemented. macro_rules! impl_color_sub { ($self_ty: ident , [$($element: ident),+]) => { impl_color_sub!($self_ty<>, [$($element),+]); }; ($self_ty: ident < $($ty_param: ident),* > , [$($element: ident),+] $(, $phantom: ident)?) => { impl<$($ty_param,)* T> core::ops::Sub for $self_ty<$($ty_param,)* T> where T: core::ops::Sub { type Output = Self; fn sub(self, other: Self) -> Self::Output { $self_ty { $($element: self.$element - other.$element,)+ $($phantom: core::marker::PhantomData,)? } } } impl<$($ty_param,)* T> core::ops::Sub for $self_ty<$($ty_param,)* T> where T: core::ops::Sub + Clone { type Output = Self; fn sub(self, c: T) -> Self::Output { $self_ty { $($element: self.$element - c.clone(),)+ $($phantom: core::marker::PhantomData,)? } } } impl<$($ty_param,)* T> core::ops::SubAssign for $self_ty<$($ty_param,)* T> where T: core::ops::SubAssign, { fn sub_assign(&mut self, other: Self) { $( self.$element -= other.$element; )+ } } impl<$($ty_param,)* T> core::ops::SubAssign for $self_ty<$($ty_param,)* T> where T: core::ops::SubAssign + Clone { fn sub_assign(&mut self, c: T) { $( self.$element -= c.clone(); )+ } } impl<$($ty_param,)* T> $crate::num::SaturatingSub for $self_ty<$($ty_param,)* T> where T: $crate::num::SaturatingSub { type Output = Self; fn saturating_sub(self, other: Self) -> Self::Output { $self_ty { $($element: self.$element.saturating_sub(other.$element),)+ $($phantom: core::marker::PhantomData,)? } } } impl<$($ty_param,)* T> $crate::num::SaturatingSub for $self_ty<$($ty_param,)* T> where T: $crate::num::SaturatingSub + Clone { type Output = Self; fn saturating_sub(self, c: T) -> Self::Output { $self_ty { $($element: self.$element.saturating_sub(c.clone()),)+ $($phantom: core::marker::PhantomData,)? } } } }; } /// Implement `Mul` and `MulAssign` traits for a color space. /// /// Both scalars and color arithmetic are implemented. macro_rules! impl_color_mul { ($self_ty: ident , [$($element: ident),+]) => { impl_color_mul!($self_ty<>, [$($element),+]); }; ($self_ty: ident < $($ty_param: ident),* > , [$($element: ident),+] $(, $phantom: ident)?) => { impl<$($ty_param,)* T> core::ops::Mul for $self_ty<$($ty_param,)* T> where T: core::ops::Mul { type Output = Self; fn mul(self, other: Self) -> Self::Output { $self_ty { $($element: self.$element * other.$element,)+ $($phantom: core::marker::PhantomData,)? } } } impl<$($ty_param,)* T> core::ops::Mul for $self_ty<$($ty_param,)* T> where T: core::ops::Mul + Clone { type Output = Self; fn mul(self, c: T) -> Self::Output { $self_ty { $($element: self.$element * c.clone(),)+ $($phantom: core::marker::PhantomData,)? } } } impl<$($ty_param,)* T> core::ops::MulAssign for $self_ty<$($ty_param,)* T> where T: core::ops::MulAssign, { fn mul_assign(&mut self, other: Self) { $( self.$element *= other.$element; )+ } } impl<$($ty_param,)* T> core::ops::MulAssign for $self_ty<$($ty_param,)* T> where T: core::ops::MulAssign + Clone { fn mul_assign(&mut self, c: T) { $( self.$element *= c.clone(); )+ } } }; } /// Implement `Div` and `DivAssign` traits for a color space. /// /// Both scalars and color arithmetic are implemented. macro_rules! impl_color_div { ($self_ty: ident , [$($element: ident),+]) => { impl_color_div!($self_ty<>, [$($element),+]); }; ($self_ty: ident < $($ty_param: ident),* > , [$($element: ident),+] $(, $phantom: ident)?) => { impl<$($ty_param,)* T> core::ops::Div for $self_ty<$($ty_param,)* T> where T: core::ops::Div { type Output = Self; fn div(self, other: Self) -> Self::Output { $self_ty { $($element: self.$element / other.$element,)+ $($phantom: core::marker::PhantomData,)? } } } impl<$($ty_param,)* T> core::ops::Div for $self_ty<$($ty_param,)* T> where T: core::ops::Div + Clone { type Output = Self; fn div(self, c: T) -> Self::Output { $self_ty { $($element: self.$element / c.clone(),)+ $($phantom: core::marker::PhantomData,)? } } } impl<$($ty_param,)* T> core::ops::DivAssign for $self_ty<$($ty_param,)* T> where T: core::ops::DivAssign, { fn div_assign(&mut self, other: Self) { $( self.$element /= other.$element; )+ } } impl<$($ty_param,)* T> core::ops::DivAssign for $self_ty<$($ty_param,)* T> where T: core::ops::DivAssign + Clone { fn div_assign(&mut self, c: T) { $( self.$element /= c.clone(); )+ } } }; }