operator
Rust !: invert Boolean values and integer bits
Prefix `!` flips a Boolean. On fixed-width integers it flips every bit instead; Rust does not convert an integer to a Boolean implicitly. Expected output (not executed): true 11110000 Why: The Boolean is inverted and all eight bits of the mask are flipped. Common mistake: `!0_u8` is 255, not true. The bit width matters. Advanced connection: `std::ops::Not`.
Formal Syntax & Structure
rust syntaxrust
!valueWorking Example
Example Snippetrust
fn main() { let is_closed = false; println!("{}", !is_closed); let mask = 0b0000_1111_u8; println!("{:08b}", !mask);}