Trait core::ops::Neg1.0.0[][src]

pub trait Neg {
    type Output;
    #[must_use]
    fn neg(self) -> Self::Output;
}
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);
Run

Associated Types

type Output[src]

The resulting type after applying the - operator.

Required methods

#[must_use]
fn neg(self) -> Self::Output
[src]

Performs the unary - operation.

Example

let x: i32 = 12;
assert_eq!(-x, -12);
Run

Implementors

impl Neg for &Wrapping<i8>1.14.0[src]

type Output = <Wrapping<i8> as Neg>::Output

fn neg(self) -> <Wrapping<i8> as Neg>::Output[src]

impl Neg for &Wrapping<i16>1.14.0[src]

type Output = <Wrapping<i16> as Neg>::Output

fn neg(self) -> <Wrapping<i16> as Neg>::Output[src]

impl Neg for &Wrapping<i32>1.14.0[src]

type Output = <Wrapping<i32> as Neg>::Output

fn neg(self) -> <Wrapping<i32> as Neg>::Output[src]

impl Neg for &Wrapping<i64>1.14.0[src]

type Output = <Wrapping<i64> as Neg>::Output

fn neg(self) -> <Wrapping<i64> as Neg>::Output[src]

impl Neg for &Wrapping<i128>1.14.0[src]

type Output = <Wrapping<i128> as Neg>::Output

fn neg(self) -> <Wrapping<i128> as Neg>::Output[src]

impl Neg for &Wrapping<isize>1.14.0[src]

type Output = <Wrapping<isize> as Neg>::Output

fn neg(self) -> <Wrapping<isize> as Neg>::Output[src]

impl Neg for &Wrapping<u8>1.14.0[src]

type Output = <Wrapping<u8> as Neg>::Output

fn neg(self) -> <Wrapping<u8> as Neg>::Output[src]

impl Neg for &Wrapping<u16>1.14.0[src]

type Output = <Wrapping<u16> as Neg>::Output

fn neg(self) -> <Wrapping<u16> as Neg>::Output[src]

impl Neg for &Wrapping<u32>1.14.0[src]

type Output = <Wrapping<u32> as Neg>::Output

fn neg(self) -> <Wrapping<u32> as Neg>::Output[src]

impl Neg for &Wrapping<u64>1.14.0[src]

type Output = <Wrapping<u64> as Neg>::Output

fn neg(self) -> <Wrapping<u64> as Neg>::Output[src]

impl Neg for &Wrapping<u128>1.14.0[src]

type Output = <Wrapping<u128> as Neg>::Output

fn neg(self) -> <Wrapping<u128> as Neg>::Output[src]

impl Neg for &Wrapping<usize>1.14.0[src]

type Output = <Wrapping<usize> as Neg>::Output

fn neg(self) -> <Wrapping<usize> as Neg>::Output[src]

impl Neg for &f32[src]

type Output = <f32 as Neg>::Output

fn neg(self) -> <f32 as Neg>::Output[src]

impl Neg for &f64[src]

type Output = <f64 as Neg>::Output

fn neg(self) -> <f64 as Neg>::Output[src]

impl Neg for &i8[src]

type Output = <i8 as Neg>::Output

fn neg(self) -> <i8 as Neg>::Output[src]

impl Neg for &i16[src]

type Output = <i16 as Neg>::Output

fn neg(self) -> <i16 as Neg>::Output[src]

impl Neg for &i32[src]

type Output = <i32 as Neg>::Output

fn neg(self) -> <i32 as Neg>::Output[src]

impl Neg for &i64[src]

type Output = <i64 as Neg>::Output

fn neg(self) -> <i64 as Neg>::Output[src]

impl Neg for &i128[src]

type Output = <i128 as Neg>::Output

fn neg(self) -> <i128 as Neg>::Output[src]

impl Neg for &isize[src]

type Output = <isize as Neg>::Output

fn neg(self) -> <isize as Neg>::Output[src]

impl Neg for Wrapping<i8>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<i16>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<i32>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<i64>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<i128>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<isize>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<u8>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<u16>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<u32>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<u64>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<u128>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for Wrapping<usize>1.10.0[src]

type Output = Self

fn neg(self) -> Self[src]

impl Neg for f32[src]

type Output = f32

fn neg(self) -> f32[src]

impl Neg for f64[src]

type Output = f64

fn neg(self) -> f64[src]

impl Neg for i8[src]

type Output = i8

fn neg(self) -> i8[src]

impl Neg for i16[src]

type Output = i16

fn neg(self) -> i16[src]

impl Neg for i32[src]

type Output = i32

fn neg(self) -> i32[src]

impl Neg for i64[src]

type Output = i64

fn neg(self) -> i64[src]

impl Neg for i128[src]

type Output = i128

fn neg(self) -> i128[src]

impl Neg for isize[src]

type Output = isize

fn neg(self) -> isize[src]