Trait az::OverflowingCastFrom

source ·
pub trait OverflowingCastFrom<Src>: Sized {
    // Required method
    fn overflowing_cast_from(src: Src) -> (Self, bool);
}
Expand description

Used for overflowing casts.

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

§Examples

use az::OverflowingCastFrom;
trait Tr {
    type Assoc: OverflowingCastFrom<u8>;
    fn overflowing_assoc_from_u8(a: u8) -> (Self::Assoc, bool) {
        OverflowingCastFrom::overflowing_cast_from(a)
    }
}
impl Tr for () {
    type Assoc = i8;
}
assert_eq!(<() as Tr>::overflowing_assoc_from_u8(5u8), (5i8, false));
assert_eq!(<() as Tr>::overflowing_assoc_from_u8(255u8), (-1i8, true));

Required Methods§

source

fn overflowing_cast_from(src: Src) -> (Self, bool)

Casts the value.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Src: OverflowingCast<Dst>, Dst> OverflowingCastFrom<Src> for Dst