Closed Boscop closed 5 years ago
Would it be possible to add AddAssign, MulAssign, SubAssign? Would be very useful when wrapping the RGB type in a newtype struct, like this:
#[shrinkwrap(mutable)] #[derive(Copy, Clone, PartialEq, Shrinkwrap, From)] pub struct Col(pub RGB<f32>);
I had to do this to get const-fn multiplication, so that I can use it for constants:
impl Col { pub const fn brightness(&self, b: f32) -> Self { Col(RGB { r: self.0.r * b, g: self.0.g * b, b: self.0.b * b }) } }
So currently I have to write:
pub fn add_col(&mut self, sel: LaunchpadButtonSelector, col: Col) { let s = &mut *self.target_state[sel]; *s = *s + *col; }
But I'd prefer to write:
pub fn add_col(&mut self, sel: LaunchpadButtonSelector, col: Col) { self.target_state[sel] += *col; }
That would be useful indeed. Could you make a pull request for it?
The regular Add/Sub implementation is in the ops module.
Add
Sub
ops
Would it be possible to add AddAssign, MulAssign, SubAssign? Would be very useful when wrapping the RGB type in a newtype struct, like this:
I had to do this to get const-fn multiplication, so that I can use it for constants:
So currently I have to write:
But I'd prefer to write: