I implemented the {Add, Div, Mul, Sub}Assign because I believe they make the code cleaner and easier to follow. I didn't write any tests because the implementations are very simply piggy-backing on the code you've already written, but am happy to add some if you'd like.
I want to note that the assignment operators are not identical to the non-assignment counterparts because I didn't find any documentation on this. When using the assignment operators first the right-hand side of the <op>= symbol is calculated and then <op> operates on that and the left-hand side. So one needs to be careful order of operations are respected:
fn main() {
let mut x = 4;
x *= 2 + 5;
println!("{:?}", x);
let mut x = 4;
x = x * 2 + 5;
println!("{:?}", x);
}
I implemented the
{Add, Div, Mul, Sub}Assign
because I believe they make the code cleaner and easier to follow. I didn't write any tests because the implementations are very simply piggy-backing on the code you've already written, but am happy to add some if you'd like.I want to note that the assignment operators are not identical to the non-assignment counterparts because I didn't find any documentation on this. When using the assignment operators first the right-hand side of the
<op>=
symbol is calculated and then<op>
operates on that and the left-hand side. So one needs to be careful order of operations are respected:This is relevant in https://github.com/SpinResearch/RustySecrets/compare/SpinResearch:3de1689...nvesely:f3f16dc#diff-6dad4b2a3f944968075fe32bae709406R40