Trait num_traits::AsPrimitive [] [src]

pub trait AsPrimitive<T>: 'static + Copy where
    T: 'static + Copy
{ fn as_(self) -> T; }

A generic interface for casting between machine scalars with the as operator, which admits narrowing and precision loss. Implementers of this trait AsPrimitive should behave like a primitive numeric type (e.g. a newtype around another primitive), and the intended conversion must never fail.

Examples

let three: i32 = (3.14159265f32).as_();
assert_eq!(three, 3);

Safety

Currently, some uses of the as operator are not entirely safe. In particular, it is undefined behavior if:

This example is not tested
let x: u8 = (1.04E+17).as_(); // UB
This example is not tested
let x: f32 = (1e300f64).as_(); // UB

Required Methods

Convert a value to another, using the as operator.

Implementations on Foreign Types

impl AsPrimitive<f64> for i16
[src]

[src]

impl AsPrimitive<u32> for i64
[src]

[src]

impl AsPrimitive<usize> for f64
[src]

[src]

impl AsPrimitive<f64> for i8
[src]

[src]

impl AsPrimitive<i8> for i16
[src]

[src]

impl AsPrimitive<i32> for isize
[src]

[src]

impl AsPrimitive<i8> for f32
[src]

[src]

impl AsPrimitive<u8> for u32
[src]

[src]

impl AsPrimitive<u32> for u32
[src]

[src]

impl AsPrimitive<u64> for f64
[src]

[src]

impl AsPrimitive<f64> for i64
[src]

[src]

impl AsPrimitive<isize> for i64
[src]

[src]

impl AsPrimitive<f32> for u32
[src]

[src]

impl AsPrimitive<u32> for char
[src]

[src]

impl AsPrimitive<u64> for i16
[src]

[src]

impl AsPrimitive<u32> for i32
[src]

[src]

impl AsPrimitive<u8> for u8
[src]

[src]

impl AsPrimitive<i16> for isize
[src]

[src]

impl AsPrimitive<u8> for bool
[src]

[src]

impl AsPrimitive<i64> for bool
[src]

[src]

impl AsPrimitive<u8> for u64
[src]

[src]

impl AsPrimitive<i16> for i8
[src]

[src]

impl AsPrimitive<u16> for i16
[src]

[src]

impl AsPrimitive<usize> for i64
[src]

[src]

impl AsPrimitive<i8> for i64
[src]

[src]

impl AsPrimitive<u16> for isize
[src]

[src]

impl AsPrimitive<i16> for u8
[src]

[src]

impl AsPrimitive<i64> for u32
[src]

[src]

impl AsPrimitive<f64> for f64
[src]

[src]

impl AsPrimitive<u32> for usize
[src]

[src]

impl AsPrimitive<u64> for u32
[src]

[src]

impl AsPrimitive<usize> for u8
[src]

[src]

impl AsPrimitive<f32> for usize
[src]

[src]

impl AsPrimitive<u8> for i64
[src]

[src]

impl AsPrimitive<f64> for usize
[src]

[src]

impl AsPrimitive<f64> for u64
[src]

[src]

impl AsPrimitive<i64> for i16
[src]

[src]

impl AsPrimitive<usize> for isize
[src]

[src]

impl AsPrimitive<isize> for f64
[src]

[src]

impl AsPrimitive<i8> for isize
[src]

[src]

impl AsPrimitive<u16> for u16
[src]

[src]

impl AsPrimitive<i16> for u64
[src]

[src]

impl AsPrimitive<isize> for u64
[src]

[src]

impl AsPrimitive<u64> for char
[src]

[src]

impl AsPrimitive<u32> for u16
[src]

[src]

impl AsPrimitive<i16> for usize
[src]

[src]

impl AsPrimitive<i32> for bool
[src]

[src]

impl AsPrimitive<isize> for u32
[src]

[src]

impl AsPrimitive<u64> for u64
[src]

[src]

impl AsPrimitive<usize> for u16
[src]

[src]

impl AsPrimitive<i64> for i8
[src]

[src]

impl AsPrimitive<f32> for i16
[src]

[src]

impl AsPrimitive<usize> for i16
[src]

[src]

impl AsPrimitive<u16> for f64
[src]

[src]

impl AsPrimitive<f64> for u8
[src]

[src]

impl AsPrimitive<isize> for isize
[src]

[src]

impl AsPrimitive<f64> for u32
[src]

[src]

impl AsPrimitive<usize> for u64
[src]

[src]

impl AsPrimitive<i64> for i32
[src]

[src]

impl AsPrimitive<i64> for u8
[src]

[src]

impl AsPrimitive<i64> for f64
[src]

[src]

impl AsPrimitive<u64> for usize
[src]

[src]

impl AsPrimitive<f32> for i32
[src]

[src]

impl AsPrimitive<i64> for u16
[src]

[src]

impl AsPrimitive<isize> for i32
[src]

[src]

impl AsPrimitive<u32> for u64
[src]

[src]

impl AsPrimitive<usize> for char
[src]

[src]

impl AsPrimitive<usize> for f32
[src]

[src]

impl AsPrimitive<i64> for u64
[src]

[src]

impl AsPrimitive<u16> for u8
[src]

[src]

impl AsPrimitive<f64> for f32
[src]

[src]

impl AsPrimitive<usize> for i8
[src]

[src]

impl AsPrimitive<i32> for f64
[src]

[src]

impl AsPrimitive<u32> for i16
[src]

[src]

impl AsPrimitive<u64> for i8
[src]

[src]

impl AsPrimitive<f32> for f64
[src]

[src]

impl AsPrimitive<f32> for u16
[src]

[src]

impl AsPrimitive<i32> for i16
[src]

[src]

impl AsPrimitive<isize> for char
[src]

[src]

impl AsPrimitive<u32> for f32
[src]

[src]

impl AsPrimitive<f32> for i8
[src]

[src]

impl AsPrimitive<u16> for u32
[src]

[src]

impl AsPrimitive<i16> for u32
[src]

[src]

impl AsPrimitive<u64> for i32
[src]

[src]

impl AsPrimitive<f64> for i32
[src]

[src]

impl AsPrimitive<u8> for i16
[src]

[src]

impl AsPrimitive<u32> for f64
[src]

[src]

impl AsPrimitive<isize> for usize
[src]

[src]

impl AsPrimitive<u16> for f32
[src]

[src]

impl AsPrimitive<i16> for i64
[src]

[src]

impl AsPrimitive<isize> for i16
[src]

[src]

impl AsPrimitive<f32> for f32
[src]

[src]

impl AsPrimitive<usize> for i32
[src]

[src]

impl AsPrimitive<u16> for i8
[src]

[src]

impl AsPrimitive<i64> for isize
[src]

[src]

impl AsPrimitive<u8> for i32
[src]

[src]

impl AsPrimitive<u64> for i64
[src]

[src]

impl AsPrimitive<i32> for i64
[src]

[src]

impl AsPrimitive<u16> for char
[src]

[src]

impl AsPrimitive<usize> for u32
[src]

[src]

impl AsPrimitive<u8> for u16
[src]

[src]

impl AsPrimitive<u8> for i8
[src]

[src]

impl AsPrimitive<i32> for usize
[src]

[src]

impl AsPrimitive<u64> for u16
[src]

[src]

impl AsPrimitive<u32> for isize
[src]

[src]

impl AsPrimitive<isize> for u16
[src]

[src]

impl AsPrimitive<u8> for char
[src]

[src]

impl AsPrimitive<u16> for u64
[src]

[src]

impl AsPrimitive<i8> for u64
[src]

[src]

impl AsPrimitive<i8> for i8
[src]

[src]

impl AsPrimitive<i8> for u32
[src]

[src]

impl AsPrimitive<isize> for f32
[src]

[src]

impl AsPrimitive<char> for char
[src]

[src]

impl AsPrimitive<i32> for u16
[src]

[src]

impl AsPrimitive<i64> for i64
[src]

[src]

impl AsPrimitive<u16> for bool
[src]

[src]

impl AsPrimitive<u32> for u8
[src]

[src]

impl AsPrimitive<char> for u8
[src]

[src]

impl AsPrimitive<i8> for u16
[src]

[src]

impl AsPrimitive<i64> for char
[src]

[src]

impl AsPrimitive<i8> for bool
[src]

[src]

impl AsPrimitive<f64> for isize
[src]

[src]

impl AsPrimitive<isize> for bool
[src]

[src]

impl AsPrimitive<i32> for f32
[src]

[src]

impl AsPrimitive<u16> for i64
[src]

[src]

impl AsPrimitive<u8> for isize
[src]

[src]

impl AsPrimitive<i32> for i32
[src]

[src]

impl AsPrimitive<i8> for i32
[src]

[src]

impl AsPrimitive<i8> for f64
[src]

[src]

impl AsPrimitive<i8> for usize
[src]

[src]

impl AsPrimitive<u32> for bool
[src]

[src]

impl AsPrimitive<i8> for char
[src]

[src]

impl AsPrimitive<u32> for i8
[src]

[src]

impl AsPrimitive<isize> for i8
[src]

[src]

impl AsPrimitive<f32> for u64
[src]

[src]

impl AsPrimitive<i16> for u16
[src]

[src]

impl AsPrimitive<u8> for usize
[src]

[src]

impl AsPrimitive<u8> for f32
[src]

[src]

impl AsPrimitive<i64> for usize
[src]

[src]

impl AsPrimitive<u64> for f32
[src]

[src]

impl AsPrimitive<f32> for isize
[src]

[src]

impl AsPrimitive<i32> for u32
[src]

[src]

impl AsPrimitive<i16> for char
[src]

[src]

impl AsPrimitive<i32> for char
[src]

[src]

impl AsPrimitive<i32> for u8
[src]

[src]

impl AsPrimitive<u64> for bool
[src]

[src]

impl AsPrimitive<u16> for usize
[src]

[src]

impl AsPrimitive<f64> for u16
[src]

[src]

impl AsPrimitive<i64> for f32
[src]

[src]

impl AsPrimitive<usize> for bool
[src]

[src]

impl AsPrimitive<u8> for f64
[src]

[src]

impl AsPrimitive<i16> for i32
[src]

[src]

impl AsPrimitive<i16> for bool
[src]

[src]

impl AsPrimitive<i32> for i8
[src]

[src]

impl AsPrimitive<f32> for i64
[src]

[src]

impl AsPrimitive<f32> for u8
[src]

[src]

impl AsPrimitive<i16> for f32
[src]

[src]

impl AsPrimitive<u64> for isize
[src]

[src]

impl AsPrimitive<isize> for u8
[src]

[src]

impl AsPrimitive<i8> for u8
[src]

[src]

impl AsPrimitive<u16> for i32
[src]

[src]

impl AsPrimitive<i16> for i16
[src]

[src]

impl AsPrimitive<i16> for f64
[src]

[src]

impl AsPrimitive<usize> for usize
[src]

[src]

impl AsPrimitive<i32> for u64
[src]

[src]

impl AsPrimitive<u64> for u8
[src]

[src]

Implementors