std::ops::BitAnd

Trait std::ops::BitAnd

#[lang = "bitand"]
pub trait BitAnd<RHS = Self> {
    type Output;
    fn bitand(self, rhs: RHS) -> Self::Output;
}

The bitwise AND operator &.

Examples

In this example, the & operator is lifted to a trivial Scalar type.

use std::ops::BitAnd;

#[derive(Debug, PartialEq)]
struct Scalar(bool);

impl BitAnd for Scalar {
    type Output = Self;

    // rhs is the "right-hand side" of the expression `a & b`
    fn bitand(self, rhs: Self) -> Self {
        Scalar(self.0 & rhs.0)
    }
}

fn main() {
    assert_eq!(Scalar(true) & Scalar(true), Scalar(true));
    assert_eq!(Scalar(true) & Scalar(false), Scalar(false));
    assert_eq!(Scalar(false) & Scalar(true), Scalar(false));
    assert_eq!(Scalar(fa