trait

BitOr — overload | for combine independent flags

BitOr supplies the | operator. The trait consumes its receivers by value unless their types are references. Bitwise OR sets positions present in either operand. Here a generic function delegates to the trait method on small primitive operands. Expected stdout (not executed): 7 Common mistake: Using OR to remove a flag. Static Rust 2024 example; not a verified ByteMind executable assessment.

Formal Syntax & Structure

rust syntaxrust
T: std::ops::BitOr<Rhs, Output = O>

Working Example

Example Snippetrust
use std::ops::BitOr;fn combine<T, R, O>(left: T, right: R) -> O where T: BitOr<R, Output=O> { left.bitor(right) }fn main() { println!("{}", combine(0b0101u8, 0b0010u8)); }
Rust Reference