trait

Neg — unary -

Unary negation changes the sign for ordinary signed numbers. Negating the minimum signed integer overflows; use checked_neg when needed. Expected stdout (not executed): -7 Common mistake: Assuming every unsigned integer supports negation. Static Rust 2024 example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
T: std::ops::Neg<Output = O>

Working Example

Example Snippetrust
use std::ops::Neg;fn invert<T: Neg>(v:T)->T::Output { v.neg() }fn main() { println!("{}", invert(7i32)); }
Rust Reference