BitAnd

BitAnd (비트 AND 연산자 트레이트)

비트 AND 연산자 &를 위한 트레이트예요.

출처: Rust 공식 문서

본문

Rhs는 기본적으로 Self이지만, 이것이 필수는 아니에요.

pub trait BitAnd<Rhs = Self> {
    type Output;

    // 필수 메서드
    fn bitand(self, rhs: Rhs) -> Self::Output;
}

예시

use std::ops::BitAnd;

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

impl BitAnd for Scalar {
    type Output = Self;

    fn bitand(self, rhs: Self) -> Self::Output {
        Self(self.0 & rhs.0)
    }
}

더 알아보기 (Learn more)

Rust 공식 문서