operator
Rust -: subtract quantities
Binary `-` finds the difference between two compatible numbers. Unsigned integers cannot represent a negative result. Expected output (not executed): 62 Why: The purchase reduces the balance by 28. Common mistake: Do not subtract a larger unsigned quantity from a smaller one without handling underflow. Advanced connection: `std::ops::Sub`; `SubAssign` for `-=`.
Formal Syntax & Structure
rust syntaxrust
a - bWorking Example
Example Snippetrust
fn main() { let balance = 90_i32; let purchase = 28; println!("{}", balance - purchase);}