pub trait Neg {
type Output;
// Required method
fn neg(self) -> Self::Output;
}
Expand description
core
The unary negation operator -
.
Re-exported from core
::ops::
.
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);
Required Associated Types§
Required Methods§
Implementors§
1.74.0 · Source§impl Neg for &Saturating<i128>
impl Neg for &Saturating<i128>
1.74.0 · Source§impl Neg for &Saturating<isize>
impl Neg for &Saturating<isize>
§impl Neg for SignedDuration
impl Neg for SignedDuration
type Output = SignedDuration
§impl Neg for Offset
Negate this offset.
impl Neg for Offset
Negate this offset.
A positive offset becomes negative and vice versa. This is a no-op for the zero offset.
This never panics.