pub trait CheckedCast<T>: Sized {
// Required method
fn checked_cast(self) -> Option<T>;
}Expand description
Fallible value-preserving conversion between any two integer types
(the trait counterpart of std’s generic checked_cast).
Required Methods§
Sourcefn checked_cast(self) -> Option<T>
fn checked_cast(self) -> Option<T>
Converts self to the target type, returning None if the value
doesn’t fit.
use const_num_traits::CheckedCast;
let ok: Option<i8> = CheckedCast::checked_cast(100u16);
let no: Option<i8> = CheckedCast::checked_cast(300u16);
assert_eq!(ok, Some(100));
assert_eq!(no, None);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".