Trait std::ops::Not1.0.0 [] [src]

pub trait Not {
    type Output;
    fn not(self) -> Self::Output;
}

The Not trait is used to specify the functionality of unary !.

Examples

An implementation of Not for Answer, which enables the use of ! to invert its value.

use std::ops::Not;

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

impl Not for Answer {
    type Output = Answer;

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

assert_eq!(!Answer::Yes, Answer::No);
assert_eq!(!Answer::No, Answer::Yes);

Associated Types

The resulting type after applying the ! operator

Required Methods

The method for the unary ! operator

Implementors