operator

Rust unary -: reverse a numeric sign

Prefix `-` negates signed integers and floating-point numbers. Unsigned integers cannot be negated this way. Expected output (not executed): -18 Why: Negation changes the sign of the adjustment. Common mistake: Negating the smallest signed integer can overflow; use a checked operation when the value is not known to be safe. Advanced connection: `std::ops::Neg`.

Formal Syntax & Structure

rust syntaxrust
-value

Working Example

Example Snippetrust
fn main() {    let change = 18_i32;    let correction = -change;    println!("{correction}");}
Rust Reference