# [−][src]Trait num_traits::ops::checked::CheckedNeg

    pub trait CheckedNeg: Sized {
        fn checked_neg(&self) -> Option<Self>;
    }

Performs negation that returns `None` if the result can't be represented.

## Required methods

### `fn checked_neg(&self) -> Option<Self>`

Negates a number, returning `None` for results that can't be represented, like signed `MIN` values that can't be positive, or non-zero unsigned values that can't be negative.

# Examples

    use num_traits::CheckedNeg;
    use std::i32::MIN;

    assert_eq!(CheckedNeg::checked_neg(&1_i32), Some(-1));
    assert_eq!(CheckedNeg::checked_neg(&-1_i32), Some(1));
    assert_eq!(CheckedNeg::checked_neg(&MIN), None);

    assert_eq!(CheckedNeg::checked_neg(&0_u32), Some(0));
    assert_eq!(CheckedNeg::checked_neg(&1_u32), None);

Loading content...

## Implementations on Foreign Types

### `impl CheckedNeg for u8`[src]

#### `fn checked_neg(&self) -> Option<u8>`[src]

### `impl CheckedNeg for u16`[src]

#### `fn checked_neg(&self) -> Option<u16>`[src]

### `impl CheckedNeg for u32`[src]

#### `fn checked_neg(&self) -> Option<u32>`[src]

### `impl CheckedNeg for u64`[src]

#### `fn checked_neg(&self) -> Option<u64>`[src]

### `impl CheckedNeg for usize`[src]

#### `fn checked_neg(&self) -> Option<usize>`[src]

### `impl CheckedNeg for u128`[src]

#### `fn checked_neg(&self) -> Option<u128>`[src]

### `impl CheckedNeg for i8`[src]

#### `fn checked_neg(&self) -> Option<i8>`[src]

### `impl CheckedNeg for i16`[src]

#### `fn checked_neg(&self) -> Option<i16>`[src]

### `impl CheckedNeg for i32`[src]

#### `fn checked_neg(&self) -> Option<i32>`[src]

### `impl CheckedNeg for i64`[src]

#### `fn checked_neg(&self) -> Option<i64>`[src]

### `impl CheckedNeg for isize`[src]

#### `fn checked_neg(&self) -> Option<isize>`[src]

### `impl CheckedNeg for i128`[src]

#### `fn checked_neg(&self) -> Option<i128>`[src]

Loading content...

## Implementors

Loading content...

# 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
`+`
  Expand all sections
`-`
  Collapse 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`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)