Expand description
The unary negation operator -
.
Examples
An implementation of Neg
for Sign
, which allows the use of -
to
negate its value.
use std::ops::Neg;
#[derive(Debug, PartialEq)]
enum Sign {
Negative,
Zero,
Positive,
}
impl Neg for Sign {
type Output = Self;
fn neg(self) -> Self::Output {
match self {
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);
RunRequired Associated Types
Required Methods
Implementors
sourceimpl Neg for &Saturating<i8>
impl Neg for &Saturating<i8>
type Output = <Saturating<i8> as Neg>::Output
sourceimpl Neg for &Saturating<i16>
impl Neg for &Saturating<i16>
type Output = <Saturating<i16> as Neg>::Output
sourceimpl Neg for &Saturating<i32>
impl Neg for &Saturating<i32>
type Output = <Saturating<i32> as Neg>::Output
sourceimpl Neg for &Saturating<i64>
impl Neg for &Saturating<i64>
type Output = <Saturating<i64> as Neg>::Output
sourceimpl Neg for &Saturating<i128>
impl Neg for &Saturating<i128>
type Output = <Saturating<i128> as Neg>::Output
sourceimpl Neg for &Saturating<isize>
impl Neg for &Saturating<isize>
type Output = <Saturating<isize> as Neg>::Output
sourceimpl Neg for vector_float
Available on PowerPC or PowerPC-64 only.
impl Neg for vector_float
Available on PowerPC or PowerPC-64 only.
type Output = vector_float
sourceimpl Neg for vector_signed_char
Available on PowerPC or PowerPC-64 only.
impl Neg for vector_signed_char
Available on PowerPC or PowerPC-64 only.
type Output = vector_signed_char
sourceimpl Neg for vector_signed_int
Available on PowerPC or PowerPC-64 only.
impl Neg for vector_signed_int
Available on PowerPC or PowerPC-64 only.
type Output = vector_signed_int
sourceimpl Neg for vector_signed_short
Available on PowerPC or PowerPC-64 only.
impl Neg for vector_signed_short
Available on PowerPC or PowerPC-64 only.