[][src]Trait az::CheckedAs

pub trait CheckedAs {
    fn checked_as<Dst>(self) -> Option<Dst>
        Self: CheckedCast<Dst>
; }

Used for checked casts.

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

This is a convenience trait to enable writing src.checked_as::<Dst>(). This would not work with the CheckedCast::checked_cast method because the CheckedCast trait is generic while the checked_cast method is not generic.

This trait’s method is suitable for chaining.


use az::CheckedAs;
use core::f32;

assert_eq!(5i32.checked_as::<u32>(), Some(5));
assert_eq!((-5i32).checked_as::<u32>(), None);
assert_eq!(17.1f32.checked_as::<u8>(), Some(17));
assert_eq!(f32::NAN.checked_as::<u8>(), None);

Required methods

fn checked_as<Dst>(self) -> Option<Dst> where
    Self: CheckedCast<Dst>, 

Casts the value.

Loading content...


impl<T> CheckedAs for T[src]

Loading content...