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§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Implementors§
impl<T> CastFrom<T> for Overflowing<i8>
overflowing only.impl<T> CastFrom<T> for Overflowing<i16>
overflowing only.impl<T> CastFrom<T> for Overflowing<i32>
overflowing only.impl<T> CastFrom<T> for Overflowing<i64>
overflowing only.impl<T> CastFrom<T> for Overflowing<i128>
overflowing only.impl<T> CastFrom<T> for Overflowing<u8>
overflowing only.impl<T> CastFrom<T> for Overflowing<u16>
overflowing only.impl<T> CastFrom<T> for Overflowing<u32>
overflowing only.impl<T> CastFrom<T> for Overflowing<u64>
overflowing only.impl<T> CastFrom<T> for Overflowing<u128>
overflowing only.