The BitXor trait enables the ^ operator for types that implement it. This operator is used for computing the bitwise exclusive or value of two integers, but has different meanings for various other data types.
Implementing BitXor looks like this:
pub enum BitExample {
Yes,
No,
}
impl BitXor for BitExample {
type Output = BitExample;
fn bitxor(self, other: BitExample) -> BitExample {
match (self, other) {
(BitExample::Yes, BitExample::Yes) => BitExample::No,
(BitExample::No, BitExample::Yes) => BitExample::Yes,
(BitExample::Yes, BitExample::No) => BitExample::Yes,
(BitExample::No, BitExample::No) => BitExample::No,
}
}
}