diff -r 6f22e4d277b4 -r 9b782aa6b452 src/direct_product.rs --- a/src/direct_product.rs Thu May 01 01:25:27 2025 -0500 +++ b/src/direct_product.rs Thu May 01 01:31:25 2025 -0500 @@ -39,32 +39,6 @@ } } -macro_rules! impl_assignop { - (($a : ty, $b : ty), $trait : ident, $fn : ident, $refr:ident) => { - impl_assignop!(@doit: $a, $b, - $trait, $fn; - maybe_lifetime!($refr, &'r Pair), - (maybe_lifetime!($refr, &'r Ai), - maybe_lifetime!($refr, &'r Bi)); - $refr); - }; - (@doit: $a : ty, $b : ty, - $trait:ident, $fn:ident; - $in:ty, ($ain:ty, $bin:ty); - $refr:ident) => { - impl<'r, Ai, Bi> $trait<$in> - for Pair<$a,$b> - where $a: $trait<$ain>, - $b: $trait<$bin> { - #[inline] - fn $fn(&mut self, y : $in) -> () { - self.0.$fn(maybe_ref!($refr, y.0)); - self.1.$fn(maybe_ref!($refr, y.1)); - } - } - } -} - // macro_rules! impl_scalarop { // (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident, $refl:ident) => { // impl_scalarop!(@doit: $field, @@ -250,16 +224,46 @@ }; } +macro_rules! impl_binary_mut { + ($trait:ident, $fn:ident) => { + impl<'a, A, B, C, D> $trait> for Pair + where + A: $trait, + B: $trait, + { + fn $fn(&mut self, Pair(c, d): Pair) { + let Pair(ref mut a, ref mut b) = self; + a.$fn(c); + b.$fn(d); + } + } + + impl<'a, 'b, A, B, C, D> $trait<&'b Pair> for Pair + where + A: $trait<&'b C>, + B: $trait<&'b D>, + { + fn $fn(&mut self, Pair(ref c, ref d): &'b Pair) { + let Pair(ref mut a, ref mut b) = self; + a.$fn(c); + b.$fn(d); + } + } + }; +} + impl_binary!(Add, add); impl_binary!(Sub, sub); +impl_binary_mut!(AddAssign, add_assign); +impl_binary_mut!(SubAssign, sub_assign); #[macro_export] macro_rules! impl_pair_vectorspace_ops { (($a:ty, $b:ty), $field:ty) => { //impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add); //impl_pair_vectorspace_ops!(@binary, ($a, $b), Sub, sub); - impl_pair_vectorspace_ops!(@assign, ($a, $b), AddAssign, add_assign); - impl_pair_vectorspace_ops!(@assign, ($a, $b), SubAssign, sub_assign); + //impl_pair_vectorspace_ops!(@assign, ($a, $b), AddAssign, add_assign); + //impl_pair_vectorspace_ops!(@assign, ($a, $b), SubAssign, sub_assign); // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Mul, mul); // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Div, div); // Compiler overflow @@ -275,10 +279,6 @@ impl_binop!(($a, $b), $trait, $fn, noref, ref); impl_binop!(($a, $b), $trait, $fn, noref, noref); }; - (@assign, ($a : ty, $b : ty), $trait : ident, $fn :ident) => { - impl_assignop!(($a, $b), $trait, $fn, ref); - impl_assignop!(($a, $b), $trait, $fn, noref); - }; (@scalar, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn :ident) => { impl_scalarop!(($a, $b), $field, $trait, $fn, ref); impl_scalarop!(($a, $b), $field, $trait, $fn, noref);