My question is why does Rust choice such design about += ( AddAssign )
.
struct Num {
value: useize,
}
impl<'a> AddAssign<&'a Num> for Num {
fn add_assign(&mut self, other: &'a Num) {
self.value += other.value;
}
}
fn main() {
let mut num = Num { value: 42 };
let num2 = Num { value: 41 };
num += &num2; // It works
// (&mut num) += &num2; // It does not work
// cannot use `+=` on type `&mut Num`
(&mut num).add_assign(&num2); // It works
num.add_assign(&num2); // It works
Why does Rust not translate +=
to add_assign()
simply ?