pub trait StrictCast<Dst> {
// Required method
fn strict_cast(self) -> Dst;
}Expand description
Used to cast values, panicking if the value does not fit.
It is normally easier to use the StrictAs trait instead of this trait.
§Panics
This trait’s method panics if the value does not fit in the destination, even when debug assertions are not enabled.
§Examples
use az::StrictCast;
let a: u32 = 5i32.strict_cast();
assert_eq!(a, 5);
assert_eq!(StrictCast::<u8>::strict_cast(17.1f32), 17);The following panics because of overflow.
ⓘ
use az::StrictCast;
let _overflow: u32 = (-5i32).strict_cast();Required Methods§
Sourcefn strict_cast(self) -> Dst
fn strict_cast(self) -> Dst
Casts the value.