"Operator-equals" are now implementable

Minimum Rust version: 1.8

The various “operator equals” operators, such as += and -=, areimplementable via various traits. For example, to implement += ona type of your own:

  1. use std::ops::AddAssign;
  2. #[derive(Debug)]
  3. struct Count {
  4. value: i32,
  5. }
  6. impl AddAssign for Count {
  7. fn add_assign(&mut self, other: Count) {
  8. self.value += other.value;
  9. }
  10. }
  11. fn main() {
  12. let mut c1 = Count { value: 1 };
  13. let c2 = Count { value: 5 };
  14. c1 += c2;
  15. println!("{:?}", c1);
  16. }

This will print Count { value: 6 }.