Trait az::CheckedCastFrom
source · [−]pub trait CheckedCastFrom<Src>: Sized {
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
fn checked_cast_from(src: Src) -> Option<Self>
fn checked_cast_from(src: Src) -> Option<Self>
Casts the value.