pub trait Neg {
type Output;
// Required method
fn neg(self) -> Self::Output;
}
Expand description
一元否定运算符 -
。
Examples
Sign
的 Neg
实现,它允许使用 -
取反其值。
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,
}
}
}
// 否定的肯定就是否定的。
assert_eq!(-Sign::Positive, Sign::Negative);
// 双重否定就是肯定。
assert_eq!(-Sign::Negative, Sign::Positive);
// 零是它自己的否定。
assert_eq!(-Sign::Zero, Sign::Zero);
RunRequired Associated Types§
Required Methods§
Implementors§
1.71.0 · source§impl Neg for &NonZeroI16
impl Neg for &NonZeroI16
type Output = <NonZeroI16 as Neg>::Output
1.71.0 · source§impl Neg for &NonZeroI32
impl Neg for &NonZeroI32
type Output = <NonZeroI32 as Neg>::Output
1.71.0 · source§impl Neg for &NonZeroI64
impl Neg for &NonZeroI64
type Output = <NonZeroI64 as Neg>::Output
1.71.0 · source§impl Neg for &NonZeroI128
impl Neg for &NonZeroI128
type Output = <NonZeroI128 as Neg>::Output
1.71.0 · source§impl Neg for &NonZeroIsize
impl Neg for &NonZeroIsize
type Output = <NonZeroIsize as Neg>::Output
source§impl 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
source§impl 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
source§impl 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
source§impl 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.