Which doesn't work if we want to perform += on a &mut BitCounts, we can't.
let mut x = BitCounts(0, 0);
let mut y = &mut x;
y += BitCounts(1, 2);
error[E0368]: binary assignment operation `+=` cannot be applied to type `&mut BitCounts`
--> src/main.rs:223:5
|
223 | y += BitCounts(1, 2);
| -^^^^^^^^^^^^^^^^^^^
| |
| cannot use `+=` on type `&mut BitCounts`
|
= note: an implementation of `std::ops::AddAssign` might be missing for `&mut BitCounts`
It would be really nice if all the necessary implementations were provided. I believe that for types T and U, the following would be necessary for addition (and obviously, replace AddAssign with the appropriate *Assign trait for other operations).
AddAssign<U> for T
AddAssign<&U> for T
AddAssign<U> for &mut T
AddAssign<&U> for &mut T
The following does work as a workaround (as a bit of an abuse of the way the macro rules are written), but is unclear.
I wanted to add a += operator to a simple tuple struct, and attempted to do
Looking at the expanded macro output, we can see the following implementations
Which doesn't work if we want to perform
+=
on a&mut BitCounts
, we can't.It would be really nice if all the necessary implementations were provided. I believe that for types
T
andU
, the following would be necessary for addition (and obviously, replaceAddAssign
with the appropriate*Assign
trait for other operations).The following does work as a workaround (as a bit of an abuse of the way the macro rules are written), but is unclear.