# Trait num_traits::cast::NumCast [−] [src]

    pub trait NumCast: Sized + ToPrimitive {
        fn from<T: ToPrimitive>(n: T) -> Option<Self>;
    }

An interface for casting between machine scalars.

## Required methods

### `fn from<T: ToPrimitive>(n: T) -> Option<Self>` [src]

Creates a number from another value that can be converted into a primitive via the `ToPrimitive` trait. If the source value cannot be represented by the target type, then `None` is returned.

A value can be represented by the target type when it lies within the range of scalars supported by the target type. For example, a negative integer cannot be represented by an unsigned integer type, and an `i64` with a very high magnitude might not be convertible to an `i32`. On the other hand, conversions with possible precision loss or truncation are admitted, like an `f32` with a decimal part to an integer type, or even a large `f64` saturating to `f32` infinity.

Loading content...

## Implementations on Foreign Types

### `impl<T: NumCast> NumCast for Wrapping<T>` [src]

#### `fn from<U: ToPrimitive>(n: U) -> Option<Self>` [src]

Loading content...

## Implementors

### `impl NumCast for f32` [src]

#### `fn from<N: ToPrimitive>(n: N) -> Option<f32>` [src]

### `impl NumCast for f64` [src]

#### `fn from<N: ToPrimitive>(n: N) -> Option<f64>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<i8>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<i16>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<i32>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<i64>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<i128>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<isize>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<u8>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<u16>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<u32>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<u64>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<u128>` [src]

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

#### `fn from<N: ToPrimitive>(n: N) -> Option<usize>` [src]

Loading content...