BitAnd

The BitAnd trait enables the & operator for types that implement it. This operator is used for computing the bitwise and value of two integers (hence the name), but has different meanings for various other data types.

Implementing BitAnd looks like this:

pub enum BitExample {
Yes,
No,
}

impl BitAnd for BitExample {
type Output = BitExample;

fn bitand(self, other: BitExample) -> BitExample {
match (self, other) {
(BitExample::Yes, BitExample::Yes) => BitExample::Yes,
(BitExample::No, BitExample::Yes) => BitExample::No,
(BitExample::Yes, BitExample::No) => BitExample::No,
(BitExample::No, BitExample::No) => BitExample::No,
}
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.21.158