Trait pprof_util::CastFrom

source ·
pub trait CastFrom<T> {
    // Required method
    fn cast_from(from: T) -> Self;
}
Expand description

A trait for safe, simple, and infallible casts.

CastFrom is like std::convert::From, but it is implemented for some platform-specific casts that are missing from the standard library. For example, there is no From<u32> for usize implementation, because Rust may someday support platforms where usize is smaller than 32 bits. Since we don’t care about such platforms, we are happy to provide a CastFrom<u32> for usize implementation.

CastFrom should be preferred to the as operator, since the as operator will silently truncate if the target type is smaller than the source type. When applicable, CastFrom should also be preferred to the std::convert::TryFrom trait, as TryFrom will produce a runtime error, while CastFrom will produce a compile-time error.

Required Methods§

source

fn cast_from(from: T) -> Self

Performs the cast.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl CastFrom<i8> for i8

source§

fn cast_from(from: i8) -> i8

source§

impl CastFrom<i8> for i16

source§

fn cast_from(from: i8) -> i16

source§

impl CastFrom<i8> for i32

source§

fn cast_from(from: i8) -> i32

source§

impl CastFrom<i8> for i64

source§

fn cast_from(from: i8) -> i64

source§

impl CastFrom<i8> for i128

source§

impl CastFrom<i8> for isize

source§

impl CastFrom<i16> for i16

source§

impl CastFrom<i16> for i32

source§

impl CastFrom<i16> for i64

source§

impl CastFrom<i16> for i128

source§

impl CastFrom<i16> for isize

source§

impl CastFrom<i32> for i32

source§

impl CastFrom<i32> for i64

source§

impl CastFrom<i32> for i128

source§

impl CastFrom<i32> for isize

source§

impl CastFrom<i64> for i64

source§

impl CastFrom<i64> for i128

source§

impl CastFrom<i64> for isize

source§

impl CastFrom<isize> for i64

source§

impl CastFrom<isize> for i128

source§

impl CastFrom<u8> for i16

source§

fn cast_from(from: u8) -> i16

source§

impl CastFrom<u8> for i32

source§

fn cast_from(from: u8) -> i32

source§

impl CastFrom<u8> for i64

source§

fn cast_from(from: u8) -> i64

source§

impl CastFrom<u8> for i128

source§

impl CastFrom<u8> for isize

source§

impl CastFrom<u8> for u8

source§

fn cast_from(from: u8) -> u8

source§

impl CastFrom<u8> for u16

source§

fn cast_from(from: u8) -> u16

source§

impl CastFrom<u8> for u32

source§

fn cast_from(from: u8) -> u32

source§

impl CastFrom<u8> for u64

source§

fn cast_from(from: u8) -> u64

source§

impl CastFrom<u8> for u128

source§

impl CastFrom<u8> for usize

source§

impl CastFrom<u16> for i32

source§

impl CastFrom<u16> for i64

source§

impl CastFrom<u16> for i128

source§

impl CastFrom<u16> for isize

source§

impl CastFrom<u16> for u16

source§

impl CastFrom<u16> for u32

source§

impl CastFrom<u16> for u64

source§

impl CastFrom<u16> for u128

source§

impl CastFrom<u16> for usize

source§

impl CastFrom<u32> for i64

source§

impl CastFrom<u32> for i128

source§

impl CastFrom<u32> for isize

source§

impl CastFrom<u32> for u32

source§

impl CastFrom<u32> for u64

source§

impl CastFrom<u32> for u128

source§

impl CastFrom<u32> for usize

source§

impl CastFrom<u64> for i128

source§

impl CastFrom<u64> for u64

source§

impl CastFrom<u64> for u128

source§

impl CastFrom<u64> for usize

source§

impl CastFrom<usize> for i128

source§

impl CastFrom<usize> for u64

source§

impl CastFrom<usize> for u128

Implementors§