pub trait Neg { typeOutput; // Required method fnneg(self) -> Self::Output;}Expand description
The unary negation operator-.
§Examples
An implementation ofNeg forSign, which allows the use of- tonegate its value.
usestd::ops::Neg;#[derive(Debug, PartialEq)]enumSign { Negative, Zero, Positive,}implNegforSign {typeOutput =Self;fnneg(self) ->Self::Output {matchself{ Sign::Negative => Sign::Positive, Sign::Zero => Sign::Zero, Sign::Positive => Sign::Negative, } }}// A negative positive is a negative.assert_eq!(-Sign::Positive, Sign::Negative);// A double negative is a positive.assert_eq!(-Sign::Negative, Sign::Positive);// Zero is its own negation.assert_eq!(-Sign::Zero, Sign::Zero);