pub trait UnwrappedCastFrom<Src> {
    fn unwrapped_cast_from(src: Src) -> Self;
}
Expand description

Used to cast values, panicking if the value does not fit.

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

Examples

use az::UnwrappedCastFrom;
trait Tr {
    type Assoc: UnwrappedCastFrom<u8>;
    fn unwrapped_assoc_from_u8(a: u8) -> Self::Assoc {
        UnwrappedCastFrom::unwrapped_cast_from(a)
    }
}
impl Tr for () {
    type Assoc = i8;
}
assert_eq!(<() as Tr>::unwrapped_assoc_from_u8(5u8), 5i8);

The following assertion would panic because of overflow.

let _overflow = <() as Tr>::unwrapped_assoc_from_u8(255u8);

Required Methods

Casts the value.

Implementors