pub trait AsPrimitive<T>: 'static + Copywhere
    T: 'static + Copy,{
    // Required method
    fn as_(self) -> T;
}
Expand description

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§

source

fn as_(self) -> T

Convert a value to another, using the as operator.

Implementations on Foreign Types§

source§

impl AsPrimitive<i128> for i32

source§

fn as_(self) -> i128

source§

impl AsPrimitive<i32> for u8

source§

fn as_(self) -> i32

source§

impl AsPrimitive<u64> for u8

source§

fn as_(self) -> u64

source§

impl AsPrimitive<u16> for u64

source§

fn as_(self) -> u16

source§

impl AsPrimitive<u32> for bool

source§

fn as_(self) -> u32

source§

impl AsPrimitive<i128> for u32

source§

fn as_(self) -> i128

source§

impl AsPrimitive<u32> for u8

source§

fn as_(self) -> u32

source§

impl AsPrimitive<i32> for bool

source§

fn as_(self) -> i32

source§

impl AsPrimitive<i64> for u8

source§

fn as_(self) -> i64

source§

impl AsPrimitive<i64> for u128

source§

fn as_(self) -> i64

source§

impl AsPrimitive<f32> for u16

source§

fn as_(self) -> f32

source§

impl AsPrimitive<u128> for u32

source§

fn as_(self) -> u128

source§

impl AsPrimitive<i64> for i128

source§

fn as_(self) -> i64

source§

impl AsPrimitive<usize> for i64

source§

fn as_(self) -> usize

source§

impl AsPrimitive<f32> for i16

source§

fn as_(self) -> f32

source§

impl AsPrimitive<i32> for u32

source§

fn as_(self) -> i32

source§

impl AsPrimitive<i128> for u16

source§

fn as_(self) -> i128

source§

impl AsPrimitive<i16> for usize

source§

fn as_(self) -> i16

source§

impl AsPrimitive<u64> for usize

source§

fn as_(self) -> u64

source§

impl AsPrimitive<isize> for isize

source§

fn as_(self) -> isize

source§

impl AsPrimitive<u32> for u128

source§

fn as_(self) -> u32

source§

impl AsPrimitive<usize> for u8

source§

fn as_(self) -> usize

source§

impl AsPrimitive<isize> for char

source§

fn as_(self) -> isize

source§

impl AsPrimitive<isize> for u32

source§

fn as_(self) -> isize

source§

impl AsPrimitive<u32> for u64

source§

fn as_(self) -> u32

source§

impl AsPrimitive<u128> for usize

source§

fn as_(self) -> u128

source§

impl AsPrimitive<i32> for f64

source§

fn as_(self) -> i32

source§

impl AsPrimitive<i16> for i8

source§

fn as_(self) -> i16

source§

impl AsPrimitive<u128> for i8

source§

fn as_(self) -> u128

source§

impl AsPrimitive<i64> for f32

source§

fn as_(self) -> i64

source§

impl AsPrimitive<u16> for f32

source§

fn as_(self) -> u16

source§

impl AsPrimitive<u64> for u64

source§

fn as_(self) -> u64

source§

impl AsPrimitive<u64> for f32

source§

fn as_(self) -> u64

source§

impl AsPrimitive<f64> for i16

source§

fn as_(self) -> f64

source§

impl AsPrimitive<i8> for i128

source§

fn as_(self) -> i8

source§

impl AsPrimitive<i64> for u64

source§

fn as_(self) -> i64

source§

impl AsPrimitive<i8> for i8

source§

fn as_(self) -> i8

source§

impl AsPrimitive<usize> for u32

source§

fn as_(self) -> usize

source§

impl AsPrimitive<i8> for i32

source§

fn as_(self) -> i8

source§

impl AsPrimitive<usize> for usize

source§

fn as_(self) -> usize

source§

impl AsPrimitive<i32> for i8

source§

fn as_(self) -> i32

source§

impl AsPrimitive<u16> for isize

source§

fn as_(self) -> u16

source§

impl AsPrimitive<i16> for f64

source§

fn as_(self) -> i16

source§

impl AsPrimitive<f32> for f32

source§

fn as_(self) -> f32

source§

impl AsPrimitive<u8> for u64

source§

fn as_(self) -> u8

source§

impl AsPrimitive<usize> for i128

source§

fn as_(self) -> usize

source§

impl AsPrimitive<usize> for i8

source§

fn as_(self) -> usize

source§

impl AsPrimitive<isize> for bool

source§

fn as_(self) -> isize

source§

impl AsPrimitive<u8> for f64

source§

fn as_(self) -> u8

source§

impl AsPrimitive<u128> for u8

source§

fn as_(self) -> u128

source§

impl AsPrimitive<u64> for i16

source§

fn as_(self) -> u64

source§

impl AsPrimitive<u8> for char

source§

fn as_(self) -> u8

source§

impl AsPrimitive<u128> for char

source§

fn as_(self) -> u128

source§

impl AsPrimitive<i16> for f32

source§

fn as_(self) -> i16

source§

impl AsPrimitive<u64> for isize

source§

fn as_(self) -> u64

source§

impl AsPrimitive<i16> for i16

source§

fn as_(self) -> i16

source§

impl AsPrimitive<i128> for u64

source§

fn as_(self) -> i128

source§

impl AsPrimitive<u8> for i128

source§

fn as_(self) -> u8

source§

impl AsPrimitive<f64> for i128

source§

fn as_(self) -> f64

source§

impl AsPrimitive<f32> for u64

source§

fn as_(self) -> f32

source§

impl AsPrimitive<u32> for f64

source§

fn as_(self) -> u32

source§

impl AsPrimitive<f64> for i32

source§

fn as_(self) -> f64

source§

impl AsPrimitive<i128> for f64

source§

fn as_(self) -> i128

source§

impl AsPrimitive<isize> for u16

source§

fn as_(self) -> isize

source§

impl AsPrimitive<u128> for i128

source§

fn as_(self) -> u128

source§

impl AsPrimitive<f32> for u128

source§

fn as_(self) -> f32

source§

impl AsPrimitive<i32> for i32

source§

fn as_(self) -> i32

source§

impl AsPrimitive<usize> for bool

source§

fn as_(self) -> usize

source§

impl AsPrimitive<usize> for i16

source§

fn as_(self) -> usize

source§

impl AsPrimitive<u8> for isize

source§

fn as_(self) -> u8

source§

impl AsPrimitive<u128> for u16

source§

fn as_(self) -> u128

source§

impl AsPrimitive<i128> for i16

source§

fn as_(self) -> i128

source§

impl AsPrimitive<i64> for i64

source§

fn as_(self) -> i64

source§

impl AsPrimitive<u16> for i32

source§

fn as_(self) -> u16

source§

impl AsPrimitive<u128> for u64

source§

fn as_(self) -> u128

source§

impl AsPrimitive<i32> for usize

source§

fn as_(self) -> i32

source§

impl AsPrimitive<i8> for u64

source§

fn as_(self) -> i8

source§

impl AsPrimitive<u64> for char

source§

fn as_(self) -> u64

source§

impl AsPrimitive<u64> for bool

source§

fn as_(self) -> u64

source§

impl AsPrimitive<i128> for i128

source§

fn as_(self) -> i128

source§

impl AsPrimitive<u8> for i8

source§

fn as_(self) -> u8

source§

impl AsPrimitive<i64> for f64

source§

fn as_(self) -> i64

source§

impl AsPrimitive<i8> for u32

source§

fn as_(self) -> i8

source§

impl AsPrimitive<usize> for f64

source§

fn as_(self) -> usize

source§

impl AsPrimitive<u32> for usize

source§

fn as_(self) -> u32

source§

impl AsPrimitive<u16> for bool

source§

fn as_(self) -> u16

source§

impl AsPrimitive<u8> for i32

source§

fn as_(self) -> u8

source§

impl AsPrimitive<isize> for f32

source§

fn as_(self) -> isize

source§

impl AsPrimitive<isize> for i8

source§

fn as_(self) -> isize

source§

impl AsPrimitive<isize> for i64

source§

fn as_(self) -> isize

source§

impl AsPrimitive<i128> for f32

source§

fn as_(self) -> i128

source§

impl AsPrimitive<u32> for u32

source§

fn as_(self) -> u32

source§

impl AsPrimitive<u64> for i8

source§

fn as_(self) -> u64

source§

impl AsPrimitive<u16> for char

source§

fn as_(self) -> u16

source§

impl AsPrimitive<isize> for i32

source§

fn as_(self) -> isize

source§

impl AsPrimitive<usize> for isize

source§

fn as_(self) -> usize

source§

impl AsPrimitive<u128> for f64

source§

fn as_(self) -> u128

source§

impl AsPrimitive<f32> for f64

source§

fn as_(self) -> f32

source§

impl AsPrimitive<u32> for i64

source§

fn as_(self) -> u32

source§

impl AsPrimitive<i32> for u16

source§

fn as_(self) -> i32

source§

impl AsPrimitive<isize> for u64

source§

fn as_(self) -> isize

source§

impl AsPrimitive<f64> for u128

source§

fn as_(self) -> f64

source§

impl AsPrimitive<isize> for f64

source§

fn as_(self) -> isize

source§

impl AsPrimitive<f32> for u8

source§

fn as_(self) -> f32

source§

impl AsPrimitive<f64> for u16

source§

fn as_(self) -> f64

source§

impl AsPrimitive<usize> for i32

source§

fn as_(self) -> usize

source§

impl AsPrimitive<i8> for i64

source§

fn as_(self) -> i8

source§

impl AsPrimitive<u128> for u128

source§

fn as_(self) -> u128

source§

impl AsPrimitive<i32> for i64

source§

fn as_(self) -> i32

source§

impl AsPrimitive<u32> for i128

source§

fn as_(self) -> u32

source§

impl AsPrimitive<i128> for i64

source§

fn as_(self) -> i128

source§

impl AsPrimitive<isize> for u128

source§

fn as_(self) -> isize

source§

impl AsPrimitive<i8> for isize

source§

fn as_(self) -> i8

source§

impl AsPrimitive<u8> for i64

source§

fn as_(self) -> u8

source§

impl AsPrimitive<usize> for char

source§

fn as_(self) -> usize

source§

impl AsPrimitive<u128> for isize

source§

fn as_(self) -> u128

source§

impl AsPrimitive<i128> for u128

source§

fn as_(self) -> i128

source§

impl AsPrimitive<i64> for usize

source§

fn as_(self) -> i64

source§

impl AsPrimitive<i16> for isize

source§

fn as_(self) -> i16

source§

impl AsPrimitive<char> for u8

source§

fn as_(self) -> char

source§

impl AsPrimitive<f64> for i8

source§

fn as_(self) -> f64

source§

impl AsPrimitive<i32> for u64

source§

fn as_(self) -> i32

source§

impl AsPrimitive<i128> for char

source§

fn as_(self) -> i128

source§

impl AsPrimitive<u128> for i16

source§

fn as_(self) -> u128

source§

impl AsPrimitive<u16> for u16

source§

fn as_(self) -> u16

source§

impl AsPrimitive<i32> for i128

source§

fn as_(self) -> i32

source§

impl AsPrimitive<usize> for u128

source§

fn as_(self) -> usize

source§

impl AsPrimitive<i64> for i16

source§

fn as_(self) -> i64

source§

impl AsPrimitive<i128> for bool

source§

fn as_(self) -> i128

source§

impl AsPrimitive<f64> for i64

source§

fn as_(self) -> f64

source§

impl AsPrimitive<u16> for i64

source§

fn as_(self) -> u16

source§

impl AsPrimitive<i16> for u64

source§

fn as_(self) -> i16

source§

impl AsPrimitive<u8> for i16

source§

fn as_(self) -> u8

source§

impl AsPrimitive<i128> for u8

source§

fn as_(self) -> i128

source§

impl AsPrimitive<u64> for f64

source§

fn as_(self) -> u64

source§

impl AsPrimitive<isize> for i128

source§

fn as_(self) -> isize

source§

impl AsPrimitive<i16> for i64

source§

fn as_(self) -> i16

source§

impl AsPrimitive<u8> for u8

source§

fn as_(self) -> u8

source§

impl AsPrimitive<u64> for u32

source§

fn as_(self) -> u64

source§

impl AsPrimitive<i16> for u32

source§

fn as_(self) -> i16

source§

impl AsPrimitive<u32> for i32

source§

fn as_(self) -> u32

source§

impl AsPrimitive<f32> for i64

source§

fn as_(self) -> f32

source§

impl AsPrimitive<i32> for char

source§

fn as_(self) -> i32

source§

impl AsPrimitive<usize> for u64

source§

fn as_(self) -> usize

source§

impl AsPrimitive<i16> for u8

source§

fn as_(self) -> i16

source§

impl AsPrimitive<f64> for u32

source§

fn as_(self) -> f64

source§

impl AsPrimitive<i32> for f32

source§

fn as_(self) -> i32

source§

impl AsPrimitive<u16> for i128

source§

fn as_(self) -> u16

source§

impl AsPrimitive<u16> for u8

source§

fn as_(self) -> u16

source§

impl AsPrimitive<u8> for bool

source§

fn as_(self) -> u8

source§

impl AsPrimitive<i16> for bool

source§

fn as_(self) -> i16

source§

impl AsPrimitive<u8> for u32

source§

fn as_(self) -> u8

source§

impl AsPrimitive<i128> for usize

source§

fn as_(self) -> i128

source§

impl AsPrimitive<i8> for i16

source§

fn as_(self) -> i8

source§

impl AsPrimitive<u32> for f32

source§

fn as_(self) -> u32

source§

impl AsPrimitive<i64> for i32

source§

fn as_(self) -> i64

source§

impl AsPrimitive<u128> for bool

source§

fn as_(self) -> u128

source§

impl AsPrimitive<i32> for i16

source§

fn as_(self) -> i32

source§

impl AsPrimitive<u16> for u32

source§

fn as_(self) -> u16

source§

impl AsPrimitive<u32> for char

source§

fn as_(self) -> u32

source§

impl AsPrimitive<u32> for u16

source§

fn as_(self) -> u32

source§

impl AsPrimitive<u16> for usize

source§

fn as_(self) -> u16

source§

impl AsPrimitive<u16> for i8

source§

fn as_(self) -> u16

source§

impl AsPrimitive<f32> for i32

source§

fn as_(self) -> f32

source§

impl AsPrimitive<i32> for isize

source§

fn as_(self) -> i32

source§

impl AsPrimitive<u8> for u16

source§

fn as_(self) -> u8

source§

impl AsPrimitive<u64> for i32

source§

fn as_(self) -> u64

source§

impl AsPrimitive<u32> for isize

source§

fn as_(self) -> u32

source§

impl AsPrimitive<u8> for u128

source§

fn as_(self) -> u8

source§

impl AsPrimitive<i64> for bool

source§

fn as_(self) -> i64

source§

impl AsPrimitive<i8> for u8

source§

fn as_(self) -> i8

source§

impl AsPrimitive<i64> for u16

source§

fn as_(self) -> i64

source§

impl AsPrimitive<i128> for isize

source§

fn as_(self) -> i128

source§

impl AsPrimitive<isize> for i16

source§

fn as_(self) -> isize

source§

impl AsPrimitive<f32> for i128

source§

fn as_(self) -> f32

source§

impl AsPrimitive<u64> for u128

source§

fn as_(self) -> u64

source§

impl AsPrimitive<isize> for u8

source§

fn as_(self) -> isize

source§

impl AsPrimitive<u64> for i128

source§

fn as_(self) -> u64

source§

impl AsPrimitive<f64> for u8

source§

fn as_(self) -> f64

source§

impl AsPrimitive<u128> for i32

source§

fn as_(self) -> u128

source§

impl AsPrimitive<u128> for i64

source§

fn as_(self) -> u128

source§

impl AsPrimitive<u16> for f64

source§

fn as_(self) -> u16

source§

impl AsPrimitive<i8> for usize

source§

fn as_(self) -> i8

source§

impl AsPrimitive<isize> for usize

source§

fn as_(self) -> isize

source§

impl AsPrimitive<i64> for i8

source§

fn as_(self) -> i64

source§

impl AsPrimitive<i8> for bool

source§

fn as_(self) -> i8

source§

impl AsPrimitive<f32> for i8

source§

fn as_(self) -> f32

source§

impl AsPrimitive<usize> for f32

source§

fn as_(self) -> usize

source§

impl AsPrimitive<u64> for i64

source§

fn as_(self) -> u64

source§

impl AsPrimitive<i16> for char

source§

fn as_(self) -> i16

source§

impl AsPrimitive<usize> for u16

source§

fn as_(self) -> usize

source§

impl AsPrimitive<u16> for u128

source§

fn as_(self) -> u16

source§

impl AsPrimitive<u32> for i16

source§

fn as_(self) -> u32

source§

impl AsPrimitive<char> for char

source§

fn as_(self) -> char

source§

impl AsPrimitive<i64> for isize

source§

fn as_(self) -> i64

source§

impl AsPrimitive<u32> for i8

source§

fn as_(self) -> u32

source§

impl AsPrimitive<i16> for i128

source§

fn as_(self) -> i16

source§

impl AsPrimitive<f64> for f32

source§

fn as_(self) -> f64

source§

impl AsPrimitive<f32> for usize

source§

fn as_(self) -> f32

source§

impl AsPrimitive<i32> for u128

source§

fn as_(self) -> i32

source§

impl AsPrimitive<i64> for u32

source§

fn as_(self) -> i64

source§

impl AsPrimitive<f64> for f64

source§

fn as_(self) -> f64

source§

impl AsPrimitive<u16> for i16

source§

fn as_(self) -> u16

source§

impl AsPrimitive<i8> for f32

source§

fn as_(self) -> i8

source§

impl AsPrimitive<f32> for isize

source§

fn as_(self) -> f32

source§

impl AsPrimitive<u8> for f32

source§

fn as_(self) -> u8

source§

impl AsPrimitive<u8> for usize

source§

fn as_(self) -> u8

source§

impl AsPrimitive<f32> for u32

source§

fn as_(self) -> f32

source§

impl AsPrimitive<i8> for u16

source§

fn as_(self) -> i8

source§

impl AsPrimitive<i16> for u128

source§

fn as_(self) -> i16

source§

impl AsPrimitive<i128> for i8

source§

fn as_(self) -> i128

source§

impl AsPrimitive<i8> for char

source§

fn as_(self) -> i8

source§

impl AsPrimitive<i8> for f64

source§

fn as_(self) -> i8

source§

impl AsPrimitive<i8> for u128

source§

fn as_(self) -> i8

source§

impl AsPrimitive<i16> for u16

source§

fn as_(self) -> i16

source§

impl AsPrimitive<i64> for char

source§

fn as_(self) -> i64

source§

impl AsPrimitive<u64> for u16

source§

fn as_(self) -> u64

source§

impl AsPrimitive<i16> for i32

source§

fn as_(self) -> i16

source§

impl AsPrimitive<f64> for u64

source§

fn as_(self) -> f64

source§

impl AsPrimitive<u128> for f32

source§

fn as_(self) -> u128

source§

impl AsPrimitive<f64> for usize

source§

fn as_(self) -> f64

source§

impl AsPrimitive<f64> for isize

source§

fn as_(self) -> f64

Implementors§