trait
BitXor — overload ^ for toggle selected bits
BitXor supplies the ^ operator. The trait consumes its receivers by value unless their types are references. Exclusive OR sets bits where operands differ. Applying the same mask twice restores the original bits. Here a generic function delegates to the trait method on small primitive operands. Expected stdout (not executed): 9 Common mistake: Treating ^ as exponentiation. Static Rust 2024 example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
T: std::ops::BitXor<Rhs, Output = O>Working Example
Example Snippetrust
use std::ops::BitXor;fn combine<T, R, O>(left: T, right: R) -> O where T: BitXor<R, Output=O> { left.bitxor(right) }fn main() { println!("{}", combine(0b1100u8, 0b0101u8)); }