Trait core::ops::BitAnd1.0.0 [] [src]

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

The BitAnd trait is used to specify the functionality of &.

Examples

In this example, the BitAnd trait is implemented for a BooleanVector struct.

fn main() { use std::ops::BitAnd; #[derive(Debug)] struct BooleanVector { value: Vec<bool>, }; impl BitAnd for BooleanVector { type Output = Self; fn bitand(self, rhs: Self) -> Self { BooleanVector { value: self.value .iter() .zip(rhs.value.iter()) .map(|(x, y)| *x && *y) .collect(), } } } impl PartialEq for BooleanVector { fn eq(&self, other: &Self) -> bool { self.value == other.value } } let bv1 = BooleanVector { value: vec![true, true, false, false] }; let bv2 = BooleanVector { value: vec![true, false, true, false] }; let expected = BooleanVector { value: vec![true, false, false, false] }; assert_eq!(bv1 & bv2, expected); }
use std::ops::BitAnd;

#[derive(Debug)]
struct BooleanVector {
    value: Vec<bool>,
};

impl BitAnd for BooleanVector {
    type Output = Self;

    fn bitand(self, rhs: Self) -> Self {
        BooleanVector {
            value: self.value
                .iter()
                .zip(rhs.value.iter())
                .map(|(x, y)| *x && *y)
                .collect(),
        }
    }
}

impl PartialEq for BooleanVector {
    fn eq(&self, other: &Self) -> bool {
        self.value == other.value
    }
}

let bv1 = BooleanVector { value: vec![true, true, false, false] };
let bv2 = BooleanVector { value: vec![true, false, true, false] };
let expected = BooleanVector { value: vec![true, false, false, false] };
assert_eq!(bv1 & bv2, expected);

Associated Types

The resulting type after applying the & operator

Required Methods

The method for the & operator

Implementors