std::ops::Neg - Rust
Description: API documentation for the Rust `Neg` trait in crate `std`.
Keywords: rust, rustlang, rust-lang, Neg

# Trait std::ops::Neg 1.0.0 [−] [src]

    #[lang = "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 = Sign;

        fn neg(self) -> Sign {
            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`

The resulting type after applying the `-` operator.

## Required Methods

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

Performs the unary `-` operation.

## Implementors

- [src]
  `impl Neg for isize type Output = isize;`
- [src]
  `impl<'a> Neg for &'a Wrapping<isize> type Output = <Wrapping<isize> as Neg>::Output;`
- [src]
  `impl<'a> Neg for &'a Wrapping<usize> type Output = <Wrapping<usize> as Neg>::Output;`
- [src]
  `impl<'a> Neg for &'a Wrapping<u8> type Output = <Wrapping<u8> as Neg>::Output;`
- [src]
  `impl<'a> Neg for &'a isize type Output = <isize as Neg>::Output;`
- [src]
  `impl Neg for Wrapping<i8> type Output = Wrapping<i8>;`
- [src]
  `impl Neg for i32 type Output = i32;`
- [src]
  `impl<'a> Neg for &'a Wrapping<u64> type Output = <Wrapping<u64> as Neg>::Output;`
- [src]
  `impl Neg for Wrapping<i128> type Output = Wrapping<i128>;`
- [src]
  `impl<'a> Neg for &'a Wrapping<i32> type Output = <Wrapping<i32> as Neg>::Output;`
- [src]
  `impl Neg for f32 type Output = f32;`
- [src]
  `impl Neg for i16 type Output = i16;`
- [src]
  `impl<'a> Neg for &'a i32 type Output = <i32 as Neg>::Output;`
- [src]
  `impl Neg for Wrapping<u8> type Output = Wrapping<u8>;`
- [src]
  `impl<'a> Neg for &'a i16 type Output = <i16 as Neg>::Output;`
- [src]
  `impl<'a> Neg for &'a Wrapping<u16> type Output = <Wrapping<u16> as Neg>::Output;`
- [src]
  `impl Neg for Wrapping<usize> type Output = Wrapping<usize>;`
- [src]
  `impl Neg for Wrapping<i32> type Output = Wrapping<i32>;`
- [src]
  `impl<'a> Neg for &'a Wrapping<i64> type Output = <Wrapping<i64> as Neg>::Output;`
- [src]
  `impl<'a> Neg for &'a f32 type Output = <f32 as Neg>::Output;`
- [src]
  `impl Neg for f64 type Output = f64;`
- [src]
  `impl Neg for Wrapping<i16> type Output = Wrapping<i16>;`
- [src]
  `impl Neg for i64 type Output = i64;`
- [src]
  `impl<'a> Neg for &'a f64 type Output = <f64 as Neg>::Output;`
- [src]
  `impl<'a> Neg for &'a i64 type Output = <i64 as Neg>::Output;`
- [src]
  `impl Neg for Wrapping<u128> type Output = Wrapping<u128>;`
- [src]
  `impl Neg for Wrapping<i64> type Output = Wrapping<i64>;`
- [src]
  `impl<'a> Neg for &'a i128 type Output = <i128 as Neg>::Output;`
- [src]
  `impl<'a> Neg for &'a Wrapping<i16> type Output = <Wrapping<i16> as Neg>::Output;`
- [src]
  `impl Neg for i8 type Output = i8;`
- [src]
  `impl<'a> Neg for &'a i8 type Output = <i8 as Neg>::Output;`
- [src]
  `impl Neg for Wrapping<u32> type Output = Wrapping<u32>;`
- [src]
  `impl<'a> Neg for &'a Wrapping<u32> type Output = <Wrapping<u32> as Neg>::Output;`
- [src]
  `impl<'a> Neg for &'a Wrapping<i128> type Output = <Wrapping<i128> as Neg>::Output;`
- [src]
  `impl Neg for Wrapping<u16> type Output = Wrapping<u16>;`
- [src]
  `impl Neg for Wrapping<isize> type Output = Wrapping<isize>;`
- [src]
  `impl<'a> Neg for &'a Wrapping<u128> type Output = <Wrapping<u128> as Neg>::Output;`
- [src]
  `impl Neg for Wrapping<u64> type Output = Wrapping<u64>;`
- [src]
  `impl Neg for i128 type Output = i128;`
- [src]
  `impl<'a> Neg for &'a Wrapping<i8> type Output = <Wrapping<i8> as Neg>::Output;`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
↑
  Move up in search results
↓
  Move down in search results
↹
  Switch tab
⏎
  Go to active search result
+ / -
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)