Add SubAssign, Add and Sub to Pixel trait requirements

This commit is contained in:
cdo committed 2026-10-26 11:42:36 +00:00
1 parent e75d56e23a
commit 26a03c002a
2 files changed
+30

No files matched your search

+24
View File
@@ -26,6 +26,12 @@ fn impl_pixel(name: syn::Ident, fields: Vec<syn::Ident>) -> TokenStream {
}
}
impl std::ops::SubAssign for #name {
fn sub_assign(&mut self, other: Self) {
#( self.#fields -= other.#fields; )*
}
}
impl std::ops::MulAssign<f32> for #name {
fn mul_assign(&mut self, scalar: f32) {
#( self.#fields *= scalar; )*
@@ -38,6 +44,24 @@ fn impl_pixel(name: syn::Ident, fields: Vec<syn::Ident>) -> TokenStream {
}
}
impl std::ops::Add for #name {
type Output = Self;
fn add(mut self, other: Self) -> Self {
self += other;
self
}
}
impl std::ops::Sub for #name {
type Output = Self;
fn sub(mut self, other: Self) -> Self {
self -= other;
self
}
}
impl std::ops::Mul<f32> for #name {
type Output = Self;
+6
View File
@@ -36,8 +36,11 @@ pub trait Format<P> {
pub trait Pixel:
std::ops::AddAssign
+ std::ops::SubAssign
+ std::ops::MulAssign<f32>
+ std::ops::DivAssign<f32>
+ std::ops::Add<Output = Self>
+ std::ops::Sub<Output = Self>
+ std::ops::Mul<f32, Output = Self>
+ std::ops::Div<f32, Output = Self>
+ Clone
@@ -51,8 +54,11 @@ pub trait Pixel:
impl<P> Pixel for P where
P: std::ops::AddAssign
+ std::ops::SubAssign
+ std::ops::MulAssign<f32>
+ std::ops::DivAssign<f32>
+ std::ops::Add<Output = Self>
+ std::ops::Sub<Output = Self>
+ std::ops::Mul<f32, Output = Self>
+ std::ops::Div<f32, Output = Self>
+ Clone