pub trait UnwrappedCast<Dst> {
// Required method
fn unwrapped_cast(self) -> Dst;
}
Expand description
Used to cast values, panicking if the value does not fit.
It is normally easier to use the UnwrappedAs
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::UnwrappedCast;
let a: u32 = 5i32.unwrapped_cast();
assert_eq!(a, 5);
assert_eq!(UnwrappedCast::<u8>::unwrapped_cast(17.1f32), 17);
The following panics because of overflow.
ⓘ
use az::UnwrappedCast;
let _overflow: u32 = (-5i32).unwrapped_cast();
Required Methods§
sourcefn unwrapped_cast(self) -> Dst
fn unwrapped_cast(self) -> Dst
Casts the value.