Not

Not (단항 논리 부정 연산자 트레이트)

단항 논리 부정 연산자 !를 위한 트레이트예요.

출처: Rust 공식 문서

본문

값을 반전시키는 단항 연산에 사용돼요.

pub trait Not {
    type Output;

    // 필수 메서드
    fn not(self) -> Self::Output;
}

예시

use std::ops::Not;

#[derive(Debug, PartialEq)]
enum Answer { Yes, No }

impl Not for Answer {
    type Output = Self;

    fn not(self) -> Self::Output {
        match self {
            Answer::Yes => Answer::No,
            Answer::No => Answer::Yes,
        }
    }
}

더 알아보기 (Learn more)

Rust 공식 문서