Trait num_traits::cast::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

In Rust versions before 1.45.0, some uses of the as operator were not entirely safe. In particular, it was undefined behavior if a truncated floating point value could not fit in the target integer type (#10184).

let x: u8 = (1.04E+17).as_(); // UB

Required methods

fn as_(self) -> T[src]

Convert a value to another, using the as operator.

Loading content...

Implementations on Foreign Types

impl AsPrimitive<char> for u8[src]

impl AsPrimitive<f32> for u8[src]

impl AsPrimitive<f64> for u8[src]

impl AsPrimitive<u8> for u8[src]

impl AsPrimitive<u16> for u8[src]

impl AsPrimitive<u32> for u8[src]

impl AsPrimitive<u64> for u8[src]

impl AsPrimitive<usize> for u8[src]

impl AsPrimitive<u128> for u8[src]

impl AsPrimitive<i8> for u8[src]

impl AsPrimitive<i16> for u8[src]

impl AsPrimitive<i32> for u8[src]

impl AsPrimitive<i64> for u8[src]

impl AsPrimitive<isize> for u8[src]

impl AsPrimitive<i128> for u8[src]

impl AsPrimitive<f32> for i8[src]

impl AsPrimitive<f64> for i8[src]

impl AsPrimitive<u8> for i8[src]

impl AsPrimitive<u16> for i8[src]

impl AsPrimitive<u32> for i8[src]

impl AsPrimitive<u64> for i8[src]

impl AsPrimitive<usize> for i8[src]

impl AsPrimitive<u128> for i8[src]

impl AsPrimitive<i8> for i8[src]

impl AsPrimitive<i16> for i8[src]

impl AsPrimitive<i32> for i8[src]

impl AsPrimitive<i64> for i8[src]

impl AsPrimitive<isize> for i8[src]

impl AsPrimitive<i128> for i8[src]

impl AsPrimitive<f32> for u16[src]

impl AsPrimitive<f64> for u16[src]

impl AsPrimitive<u8> for u16[src]

impl AsPrimitive<u16> for u16[src]

impl AsPrimitive<u32> for u16[src]

impl AsPrimitive<u64> for u16[src]

impl AsPrimitive<usize> for u16[src]

impl AsPrimitive<u128> for u16[src]

impl AsPrimitive<i8> for u16[src]

impl AsPrimitive<i16> for u16[src]

impl AsPrimitive<i32> for u16[src]

impl AsPrimitive<i64> for u16[src]

impl AsPrimitive<isize> for u16[src]

impl AsPrimitive<i128> for u16[src]

impl AsPrimitive<f32> for i16[src]

impl AsPrimitive<f64> for i16[src]

impl AsPrimitive<u8> for i16[src]

impl AsPrimitive<u16> for i16[src]

impl AsPrimitive<u32> for i16[src]

impl AsPrimitive<u64> for i16[src]

impl AsPrimitive<usize> for i16[src]

impl AsPrimitive<u128> for i16[src]

impl AsPrimitive<i8> for i16[src]

impl AsPrimitive<i16> for i16[src]

impl AsPrimitive<i32> for i16[src]

impl AsPrimitive<i64> for i16[src]

impl AsPrimitive<isize> for i16[src]

impl AsPrimitive<i128> for i16[src]

impl AsPrimitive<f32> for u32[src]

impl AsPrimitive<f64> for u32[src]

impl AsPrimitive<u8> for u32[src]

impl AsPrimitive<u16> for u32[src]

impl AsPrimitive<u32> for u32[src]

impl AsPrimitive<u64> for u32[src]

impl AsPrimitive<usize> for u32[src]

impl AsPrimitive<u128> for u32[src]

impl AsPrimitive<i8> for u32[src]

impl AsPrimitive<i16> for u32[src]

impl AsPrimitive<i32> for u32[src]

impl AsPrimitive<i64> for u32[src]

impl AsPrimitive<isize> for u32[src]

impl AsPrimitive<i128> for u32[src]

impl AsPrimitive<f32> for i32[src]

impl AsPrimitive<f64> for i32[src]

impl AsPrimitive<u8> for i32[src]

impl AsPrimitive<u16> for i32[src]

impl AsPrimitive<u32> for i32[src]

impl AsPrimitive<u64> for i32[src]

impl AsPrimitive<usize> for i32[src]

impl AsPrimitive<u128> for i32[src]

impl AsPrimitive<i8> for i32[src]

impl AsPrimitive<i16> for i32[src]

impl AsPrimitive<i32> for i32[src]

impl AsPrimitive<i64> for i32[src]

impl AsPrimitive<isize> for i32[src]

impl AsPrimitive<i128> for i32[src]

impl AsPrimitive<f32> for u64[src]

impl AsPrimitive<f64> for u64[src]

impl AsPrimitive<u8> for u64[src]

impl AsPrimitive<u16> for u64[src]

impl AsPrimitive<u32> for u64[src]

impl AsPrimitive<u64> for u64[src]

impl AsPrimitive<usize> for u64[src]

impl AsPrimitive<u128> for u64[src]

impl AsPrimitive<i8> for u64[src]

impl AsPrimitive<i16> for u64[src]

impl AsPrimitive<i32> for u64[src]

impl AsPrimitive<i64> for u64[src]

impl AsPrimitive<isize> for u64[src]

impl AsPrimitive<i128> for u64[src]

impl AsPrimitive<f32> for i64[src]

impl AsPrimitive<f64> for i64[src]

impl AsPrimitive<u8> for i64[src]

impl AsPrimitive<u16> for i64[src]

impl AsPrimitive<u32> for i64[src]

impl AsPrimitive<u64> for i64[src]

impl AsPrimitive<usize> for i64[src]

impl AsPrimitive<u128> for i64[src]

impl AsPrimitive<i8> for i64[src]

impl AsPrimitive<i16> for i64[src]

impl AsPrimitive<i32> for i64[src]

impl AsPrimitive<i64> for i64[src]

impl AsPrimitive<isize> for i64[src]

impl AsPrimitive<i128> for i64[src]

impl AsPrimitive<f32> for u128[src]

impl AsPrimitive<f64> for u128[src]

impl AsPrimitive<u8> for u128[src]

impl AsPrimitive<u16> for u128[src]

impl AsPrimitive<u32> for u128[src]

impl AsPrimitive<u64> for u128[src]

impl AsPrimitive<usize> for u128[src]

impl AsPrimitive<u128> for u128[src]

impl AsPrimitive<i8> for u128[src]

impl AsPrimitive<i16> for u128[src]

impl AsPrimitive<i32> for u128[src]

impl AsPrimitive<i64> for u128[src]

impl AsPrimitive<isize> for u128[src]

impl AsPrimitive<i128> for u128[src]

impl AsPrimitive<f32> for i128[src]

impl AsPrimitive<f64> for i128[src]

impl AsPrimitive<u8> for i128[src]

impl AsPrimitive<u16> for i128[src]

impl AsPrimitive<u32> for i128[src]

impl AsPrimitive<u64> for i128[src]

impl AsPrimitive<usize> for i128[src]

impl AsPrimitive<u128> for i128[src]

impl AsPrimitive<i8> for i128[src]

impl AsPrimitive<i16> for i128[src]

impl AsPrimitive<i32> for i128[src]

impl AsPrimitive<i64> for i128[src]

impl AsPrimitive<isize> for i128[src]

impl AsPrimitive<i128> for i128[src]

impl AsPrimitive<f32> for usize[src]

impl AsPrimitive<f64> for usize[src]

impl AsPrimitive<u8> for usize[src]

impl AsPrimitive<u16> for usize[src]

impl AsPrimitive<u32> for usize[src]

impl AsPrimitive<u64> for usize[src]

impl AsPrimitive<usize> for usize[src]

impl AsPrimitive<u128> for usize[src]

impl AsPrimitive<i8> for usize[src]

impl AsPrimitive<i16> for usize[src]

impl AsPrimitive<i32> for usize[src]

impl AsPrimitive<i64> for usize[src]

impl AsPrimitive<isize> for usize[src]

impl AsPrimitive<i128> for usize[src]

impl AsPrimitive<f32> for isize[src]

impl AsPrimitive<f64> for isize[src]

impl AsPrimitive<u8> for isize[src]

impl AsPrimitive<u16> for isize[src]

impl AsPrimitive<u32> for isize[src]

impl AsPrimitive<u64> for isize[src]

impl AsPrimitive<usize> for isize[src]

impl AsPrimitive<u128> for isize[src]

impl AsPrimitive<i8> for isize[src]

impl AsPrimitive<i16> for isize[src]

impl AsPrimitive<i32> for isize[src]

impl AsPrimitive<i64> for isize[src]

impl AsPrimitive<isize> for isize[src]

impl AsPrimitive<i128> for isize[src]

impl AsPrimitive<f32> for f32[src]

impl AsPrimitive<f64> for f32[src]

impl AsPrimitive<u8> for f32[src]

impl AsPrimitive<u16> for f32[src]

impl AsPrimitive<u32> for f32[src]

impl AsPrimitive<u64> for f32[src]

impl AsPrimitive<usize> for f32[src]

impl AsPrimitive<u128> for f32[src]

impl AsPrimitive<i8> for f32[src]

impl AsPrimitive<i16> for f32[src]

impl AsPrimitive<i32> for f32[src]

impl AsPrimitive<i64> for f32[src]

impl AsPrimitive<isize> for f32[src]

impl AsPrimitive<i128> for f32[src]

impl AsPrimitive<f32> for f64[src]

impl AsPrimitive<f64> for f64[src]

impl AsPrimitive<u8> for f64[src]

impl AsPrimitive<u16> for f64[src]

impl AsPrimitive<u32> for f64[src]

impl AsPrimitive<u64> for f64[src]

impl AsPrimitive<usize> for f64[src]

impl AsPrimitive<u128> for f64[src]

impl AsPrimitive<i8> for f64[src]

impl AsPrimitive<i16> for f64[src]

impl AsPrimitive<i32> for f64[src]

impl AsPrimitive<i64> for f64[src]

impl AsPrimitive<isize> for f64[src]

impl AsPrimitive<i128> for f64[src]

impl AsPrimitive<char> for char[src]

impl AsPrimitive<u8> for char[src]

impl AsPrimitive<u16> for char[src]

impl AsPrimitive<u32> for char[src]

impl AsPrimitive<u64> for char[src]

impl AsPrimitive<usize> for char[src]

impl AsPrimitive<u128> for char[src]

impl AsPrimitive<i8> for char[src]

impl AsPrimitive<i16> for char[src]

impl AsPrimitive<i32> for char[src]

impl AsPrimitive<i64> for char[src]

impl AsPrimitive<isize> for char[src]

impl AsPrimitive<i128> for char[src]

impl AsPrimitive<u8> for bool[src]

impl AsPrimitive<u16> for bool[src]

impl AsPrimitive<u32> for bool[src]

impl AsPrimitive<u64> for bool[src]

impl AsPrimitive<usize> for bool[src]

impl AsPrimitive<u128> for bool[src]

impl AsPrimitive<i8> for bool[src]

impl AsPrimitive<i16> for bool[src]

impl AsPrimitive<i32> for bool[src]

impl AsPrimitive<i64> for bool[src]

impl AsPrimitive<isize> for bool[src]

impl AsPrimitive<i128> for bool[src]

Loading content...

Implementors

Loading content...