Trait std::ops::Neg
pub trait Neg {
type Output;
fn neg(self) -> Self::Output;
}
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);Associated Types
type Output
The resulting type after applying the - operator.
Required methods
fn neg(self) -> Self::Output
Performs the unary - operation.
Example
let x: i32 = 12; assert_eq!(-x, -12);
Implementors
impl Neg for f32
type Output = f32
impl Neg for f64
type Output = f64
impl Neg for i8
type Output = i8
impl Neg for i16
type Output = i16
impl Neg for i32
type Output = i32
impl Neg for i64
type Output = i64
impl Neg for i128
type Output = i128
impl Neg for isize
type Output = isize
impl Neg for Saturating<i8>
type Output = Saturating<i8>
impl Neg for Saturating<i16>
type Output = Saturating<i16>
impl Neg for Saturating<i32>
type Output = Saturating<i32>
impl Neg for Saturating<i64>
type Output = Saturating<i64>
impl Neg for Saturating<i128>
type Output = Saturating<i128>
impl Neg for Saturating<isize>
type Output = Saturating<isize>
[src]1.10.0
impl Neg for Wrapping<i8>
type Output = Wrapping<i8>
[src]1.10.0
impl Neg for Wrapping<i16>
type Output = Wrapping<i16>
[src]1.10.0
impl Neg for Wrapping<i32>
type Output = Wrapping<i32>
[src]1.10.0
impl Neg for Wrapping<i64>
type Output = Wrapping<i64>
[src]1.10.0
impl Neg for Wrapping<i128>
type Output = Wrapping<i128>
[src]1.10.0
impl Neg for Wrapping<isize>
type Output = Wrapping<isize>
[src]1.10.0
impl Neg for Wrapping<u8>
type Output = Wrapping<u8>
[src]1.10.0
impl Neg for Wrapping<u16>
type Output = Wrapping<u16>
[src]1.10.0
impl Neg for Wrapping<u32>
type Output = Wrapping<u32>
[src]1.10.0
impl Neg for Wrapping<u64>
type Output = Wrapping<u64>
[src]1.10.0
impl Neg for Wrapping<u128>
type Output = Wrapping<u128>
[src]1.10.0
impl Neg for Wrapping<usize>
type Output = Wrapping<usize>
impl<'_> Neg for &'_ f32
type Output = <f32 as Neg>::Output
impl<'_> Neg for &'_ f64
type Output = <f64 as Neg>::Output
impl<'_> Neg for &'_ i8
type Output = <i8 as Neg>::Output
impl<'_> Neg for &'_ i16
type Output = <i16 as Neg>::Output
impl<'_> Neg for &'_ i32
type Output = <i32 as Neg>::Output
impl<'_> Neg for &'_ i64
type Output = <i64 as Neg>::Output
impl<'_> Neg for &'_ i128
type Output = <i128 as Neg>::Output
impl<'_> Neg for &'_ isize
type Output = <isize as Neg>::Output
impl<'_> Neg for &'_ Saturating<i8>
type Output = <Saturating<i8> as Neg>::Output
impl<'_> Neg for &'_ Saturating<i16>
type Output = <Saturating<i16> as Neg>::Output
impl<'_> Neg for &'_ Saturating<i32>
type Output = <Saturating<i32> as Neg>::Output
impl<'_> Neg for &'_ Saturating<i64>
type Output = <Saturating<i64> as Neg>::Output
impl<'_> Neg for &'_ Saturating<i128>
type Output = <Saturating<i128> as Neg>::Output
impl<'_> Neg for &'_ Saturating<isize>
type Output = <Saturating<isize> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<i8>
type Output = <Wrapping<i8> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<i16>
type Output = <Wrapping<i16> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<i32>
type Output = <Wrapping<i32> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<i64>
type Output = <Wrapping<i64> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<i128>
type Output = <Wrapping<i128> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<isize>
type Output = <Wrapping<isize> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<u8>
type Output = <Wrapping<u8> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<u16>
type Output = <Wrapping<u16> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<u32>
type Output = <Wrapping<u32> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<u64>
type Output = <Wrapping<u64> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<u128>
type Output = <Wrapping<u128> as Neg>::Output
[src]1.14.0
impl<'_> Neg for &'_ Wrapping<usize>
type Output = <Wrapping<usize> as Neg>::Output
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/ops/trait.Neg.html