# Trait Neg

1.6.0 (const: unstable) · Source

    pub trait Neg {
        type Output;

        // Required method
        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);

## Required Associated Types§

1.0.0 · Source

#### type Output

The resulting type after applying the `-` operator.

## Required Methods§

1.0.0 · Source

#### fn neg(self) -> Self::Output

Performs the unary `-` operation.

##### §Example

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

## Implementors§

1.0.0 (const: unstable) · Source§

### impl Neg for &f16

Source§

#### type Output = <f16 as Neg>::Output

1.0.0 (const: unstable) · Source§

### impl Neg for &f32

Source§

#### type Output = <f32 as Neg>::Output

1.0.0 (const: unstable) · Source§

### impl Neg for &f64

Source§

#### type Output = <f64 as Neg>::Output

1.0.0 (const: unstable) · Source§

### impl Neg for &f128

Source§

#### type Output = <f128 as Neg>::Output

1.0.0 (const: unstable) · Source§

### impl Neg for &i8

Source§

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

1.0.0 (const: unstable) · Source§

### impl Neg for &i16

Source§

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

1.0.0 (const: unstable) · Source§

### impl Neg for &i32

Source§

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

1.0.0 (const: unstable) · Source§

### impl Neg for &i64

Source§

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

1.0.0 (const: unstable) · Source§

### impl Neg for &i128

Source§

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

1.0.0 (const: unstable) · Source§

### impl Neg for &isize

Source§

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

1.71.0 (const: unstable) · Source§

### impl Neg for &NonZero<i8>

Source§

#### type Output = <NonZero<i8> as Neg>::Output

1.71.0 (const: unstable) · Source§

### impl Neg for &NonZero<i16>

Source§

#### type Output = <NonZero<i16> as Neg>::Output

1.71.0 (const: unstable) · Source§

### impl Neg for &NonZero<i32>

Source§

#### type Output = <NonZero<i32> as Neg>::Output

1.71.0 (const: unstable) · Source§

### impl Neg for &NonZero<i64>

Source§

#### type Output = <NonZero<i64> as Neg>::Output

1.71.0 (const: unstable) · Source§

### impl Neg for &NonZero<i128>

Source§

#### type Output = <NonZero<i128> as Neg>::Output

1.71.0 (const: unstable) · Source§

### impl Neg for &NonZero<isize>

Source§

#### type Output = <NonZero<isize> as Neg>::Output

1.74.0 (const: unstable) · Source§

### impl Neg for &Saturating<i8>

Source§

#### type Output = <Saturating<i8> as Neg>::Output

1.74.0 (const: unstable) · Source§

### impl Neg for &Saturating<i16>

Source§

#### type Output = <Saturating<i16> as Neg>::Output

1.74.0 (const: unstable) · Source§

### impl Neg for &Saturating<i32>

Source§

#### type Output = <Saturating<i32> as Neg>::Output

1.74.0 (const: unstable) · Source§

### impl Neg for &Saturating<i64>

Source§

#### type Output = <Saturating<i64> as Neg>::Output

1.74.0 (const: unstable) · Source§

### impl Neg for &Saturating<i128>

Source§

#### type Output = <Saturating<i128> as Neg>::Output

1.74.0 (const: unstable) · Source§

### impl Neg for &Saturating<isize>

Source§

#### type Output = <Saturating<isize> as Neg>::Output

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<i8>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<i16>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<i32>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<i64>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<i128>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<isize>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<u8>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<u16>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<u32>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<u64>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<u128>

Source§

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

1.14.0 (const: unstable) · Source§

### impl Neg for &Wrapping<usize>

Source§

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

1.0.0 (const: unstable) · Source§

### impl Neg for f16

Source§

#### type Output = f16

1.0.0 (const: unstable) · Source§

### impl Neg for f32

Source§

#### type Output = f32

1.0.0 (const: unstable) · Source§

### impl Neg for f64

Source§

#### type Output = f64

1.0.0 (const: unstable) · Source§

### impl Neg for f128

Source§

#### type Output = f128

1.0.0 (const: unstable) · Source§

### impl Neg for i8

Source§

#### type Output = i8

1.0.0 (const: unstable) · Source§

### impl Neg for i16

Source§

#### type Output = i16

1.0.0 (const: unstable) · Source§

### impl Neg for i32

Source§

#### type Output = i32

1.0.0 (const: unstable) · Source§

### impl Neg for i64

Source§

#### type Output = i64

1.0.0 (const: unstable) · Source§

### impl Neg for i128

Source§

#### type Output = i128

1.0.0 (const: unstable) · Source§

### impl Neg for isize

Source§

#### type Output = isize

Source§

### impl Neg for core::arch::powerpc::vector_float

Available on PowerPC or PowerPC-64 only.
Source§

#### type Output = vector_float

Source§

### impl Neg for core::arch::powerpc::vector_signed_char

Available on PowerPC or PowerPC-64 only.
Source§

#### type Output = vector_signed_char

Source§

### impl Neg for core::arch::powerpc::vector_signed_int

Available on PowerPC or PowerPC-64 only.
Source§

#### type Output = vector_signed_int

Source§

### impl Neg for core::arch::powerpc::vector_signed_short

Available on PowerPC or PowerPC-64 only.
Source§

#### type Output = vector_signed_short

Source§

### impl Neg for vector_double

Available on s390x only.
Source§

#### type Output = vector_double

Source§

### impl Neg for core::arch::s390x::vector_float

Available on s390x only.
Source§

#### type Output = vector_float

Source§

### impl Neg for core::arch::s390x::vector_signed_char

Available on s390x only.
Source§

#### type Output = vector_signed_char

Source§

### impl Neg for core::arch::s390x::vector_signed_int

Available on s390x only.
Source§

#### type Output = vector_signed_int

Source§

### impl Neg for vector_signed_long_long

Available on s390x only.
Source§

#### type Output = vector_signed_long_long

Source§

### impl Neg for core::arch::s390x::vector_signed_short

Available on s390x only.
Source§

#### type Output = vector_signed_short

1.71.0 (const: unstable) · Source§

### impl Neg for NonZero<i8>

Source§

#### type Output = NonZero<i8>

1.71.0 (const: unstable) · Source§

### impl Neg for NonZero<i16>

Source§

#### type Output = NonZero<i16>

1.71.0 (const: unstable) · Source§

### impl Neg for NonZero<i32>

Source§

#### type Output = NonZero<i32>

1.71.0 (const: unstable) · Source§

### impl Neg for NonZero<i64>

Source§

#### type Output = NonZero<i64>

1.71.0 (const: unstable) · Source§

### impl Neg for NonZero<i128>

Source§

#### type Output = NonZero<i128>

1.71.0 (const: unstable) · Source§

### impl Neg for NonZero<isize>

Source§

#### type Output = NonZero<isize>

1.74.0 (const: unstable) · Source§

### impl Neg for Saturating<i8>

Source§

#### type Output = Saturating<i8>

1.74.0 (const: unstable) · Source§

### impl Neg for Saturating<i16>

Source§

#### type Output = Saturating<i16>

1.74.0 (const: unstable) · Source§

### impl Neg for Saturating<i32>

Source§

#### type Output = Saturating<i32>

1.74.0 (const: unstable) · Source§

### impl Neg for Saturating<i64>

Source§

#### type Output = Saturating<i64>

1.74.0 (const: unstable) · Source§

### impl Neg for Saturating<i128>

Source§

#### type Output = Saturating<i128>

1.74.0 (const: unstable) · Source§

### impl Neg for Saturating<isize>

Source§

#### type Output = Saturating<isize>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<i8>

Source§

#### type Output = Wrapping<i8>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<i16>

Source§

#### type Output = Wrapping<i16>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<i32>

Source§

#### type Output = Wrapping<i32>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<i64>

Source§

#### type Output = Wrapping<i64>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<i128>

Source§

#### type Output = Wrapping<i128>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<isize>

Source§

#### type Output = Wrapping<isize>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<u8>

Source§

#### type Output = Wrapping<u8>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<u16>

Source§

#### type Output = Wrapping<u16>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<u32>

Source§

#### type Output = Wrapping<u32>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<u64>

Source§

#### type Output = Wrapping<u64>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<u128>

Source§

#### type Output = Wrapping<u128>

1.10.0 (const: unstable) · Source§

### impl Neg for Wrapping<usize>

Source§

#### type Output = Wrapping<usize>

Source§

### impl<const N: usize> Neg for Simd<f32, N>
where f32: SimdElement, LaneCount<N>: SupportedLaneCount,

Source§

#### type Output = Simd<f32, N>

Source§

### impl<const N: usize> Neg for Simd<f64, N>
where f64: SimdElement, LaneCount<N>: SupportedLaneCount,

Source§

#### type Output = Simd<f64, N>

Source§

### impl<const N: usize> Neg for Simd<i8, N>
where i8: SimdElement, LaneCount<N>: SupportedLaneCount,

Source§

#### type Output = Simd<i8, N>

Source§

### impl<const N: usize> Neg for Simd<i16, N>
where i16: SimdElement, LaneCount<N>: SupportedLaneCount,

Source§

#### type Output = Simd<i16, N>

Source§

### impl<const N: usize> Neg for Simd<i32, N>
where i32: SimdElement, LaneCount<N>: SupportedLaneCount,

Source§

#### type Output = Simd<i32, N>

Source§

### impl<const N: usize> Neg for Simd<i64, N>
where i64: SimdElement, LaneCount<N>: SupportedLaneCount,

Source§

#### type Output = Simd<i64, N>

Source§

### impl<const N: usize> Neg for Simd<isize, N>
where isize: SimdElement, LaneCount<N>: SupportedLaneCount,

Source§

#### type Output = Simd<isize, N>