pub trait Not {
    type Output;
    // Required method
    fn not(self) -> Self::Output;
}Expand description
一元逻辑否定运算符 !。
Examples
用于 Answer 的 Not 的实现,该实现允许使用 ! 反转其值。
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
        }
    }
}
assert_eq!(!Answer::Yes, Answer::No);
assert_eq!(!Answer::No, Answer::Yes);