Neg

The Neg trait enables a data type to be used with the unary negation operator, also known as the negative sign. When we write -5, we're applying the unary negation operator to the value 5, producing a negative 5 as the result.

Implementing Neg looks like this:

pub enum NegExample {
Yes,
No,
}

impl Neg for NegExample {
type Output = NegExample;

fn neg(self) -> NegExample {
match self {
NegExample::Yes => NegExample::No,
NegExample::No => NegExample::Yes,
}
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.137.38