Trait az::CheckedCast[][src]

pub trait CheckedCast<Dst> {
    fn checked_cast(self) -> Option<Dst>;
}
Expand description

Used for checked casts.

This trait’s method returns None if the value does not fit.

It is normally easier to use the CheckedAs trait instead of this trait.

Examples

use az::CheckedCast;
use core::f32;

let a: Option<u32> = 5i32.checked_cast();
assert_eq!(a, Some(5));
assert_eq!(CheckedCast::<u32>::checked_cast(-5i32), None);
assert_eq!(CheckedCast::<u8>::checked_cast(17.1f32), Some(17));
let b: Option<u8> = f32::NAN.checked_cast();
assert_eq!(b, None);

Required methods

Casts the value.

Implementors