pub trait TryCastFrom<T>: Sized {
// Required method
fn try_cast_from(from: T) -> Option<Self>;
}
Expand description
A trait for attempted casts.
TryCast
is like as
, but returns None
if
the conversion can’t be round-tripped.
Note: there may be holes in the domain of try_cast_from
,
which is probably why TryFrom
wasn’t implemented for floats in the
standard library. For example, i64::MAX
can be converted to
f64
, but i64::MAX - 1
can’t.
Required Methods§
Sourcefn try_cast_from(from: T) -> Option<Self>
fn try_cast_from(from: T) -> Option<Self>
Attempts to perform the cast
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.