pub trait AddAssign<Rhs = Self> {
// Required method
fn add_assign(&mut self, rhs: Rhs);
}Expand description
The addition assignment operator +=.
§Examples
This example creates a Point struct that implements the AddAssign
trait, and then demonstrates add-assigning to a mutable Point.
use std::ops::AddAssign;
#[derive(Debug, Copy, Clone, PartialEq)]
struct Point {
x: i32,
y: i32,
}
impl AddAssign for Point {
fn add_assign(&mut self, other: Self) {
*self = Self {
x: self.x + other.x,
y: self.y + other.y,
};
}
}
let mut point = Point { x: 1, y: 0 };
point += Point { x: 2, y: 3 };
assert_eq!(point, Point { x: 3, y: 3 });Required Methods§
1.8.0 (const: unstable) · Sourcefn add_assign(&mut self, rhs: Rhs)
fn add_assign(&mut self, rhs: Rhs)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".