Trait ore::cast::CastFrom [−][src]
pub trait CastFrom<T> {
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.