Trait mz_ore::cast::TryCastFrom
source · 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
Object Safety§
This trait is not object safe.