operator
Rust += -= *= /= %=: update a number in place
Compound arithmetic assignment updates a mutable place using its existing value. For simple primitive bindings this is a convenient way to express an arithmetic update. Expected output (not executed): 1 Why: The intermediate values are 15, 12, 24, 4 and 1. Common mistake: The result of the assignment is unit, and overloaded operations need not behave like textual substitution. Rust has no ++ or -- increment operators. Advanced connection: `AddAssign`, `SubAssign`, `MulAssign`, `DivAssign`, `RemAssign`.
Formal Syntax & Structure
rust syntaxrust
place += value; place -= value; place *= value; place /= value; place %= valueWorking Example
Example Snippetrust
fn main() { let mut points = 10; points += 5; points -= 3; points *= 2; points /= 5; points %= 3; println!("{points}");}