Trait az::CheckedCastFrom

source ·
pub trait CheckedCastFrom<Src>: Sized {
    // Required method
    fn checked_cast_from(src: Src) -> Option<Self>;
}
Expand description

Used for checked casts.

This trait enables trait constraints for casting in the opposite direction to CheckedCast.

Examples

use az::CheckedCastFrom;
trait Tr {
    type Assoc: CheckedCastFrom<u8>;
    fn checked_assoc_from_u8(a: u8) -> Option<Self::Assoc> {
        CheckedCastFrom::checked_cast_from(a)
    }
}
impl Tr for () {
    type Assoc = i8;
}
assert_eq!(<() as Tr>::checked_assoc_from_u8(5u8), Some(5i8));
assert_eq!(<() as Tr>::checked_assoc_from_u8(255u8), None);

Required Methods§

source

fn checked_cast_from(src: Src) -> Option<Self>

Casts the value.

Implementors§

source§

impl<Src: CheckedCast<Dst>, Dst> CheckedCastFrom<Src> for Dst