operator
Rust |: set selected bits
Integer `|` sets a bit if either operand contains a one at that position. It is useful for combining flags. Expected output (not executed): 0101 Why: The original flag and the additional flag remain set. Common mistake: OR does not toggle bits. On bool, `|` is eager logical OR. Advanced connection: `std::ops::BitOr`; `BitOrAssign` for `|=`.
Formal Syntax & Structure
rust syntaxrust
a | bWorking Example
Example Snippetrust
fn main() { let flags = 0b0001_u8; let extra = 0b0100_u8; println!("{:04b}", flags | extra);}