Trait az::SaturatingCastFrom
source · [−]pub trait SaturatingCastFrom<Src> {
fn saturating_cast_from(src: Src) -> Self;
}
Expand description
Used to cast, saturating if the value does not fit.
This trait enables trait constraints for casting in the opposite direction to
SaturatingCast
.
Examples
use az::SaturatingCastFrom;
trait Tr {
type Assoc: SaturatingCastFrom<u8>;
fn saturating_assoc_from_u8(a: u8) -> Self::Assoc {
SaturatingCastFrom::saturating_cast_from(a)
}
}
impl Tr for () {
type Assoc = i8;
}
assert_eq!(<() as Tr>::saturating_assoc_from_u8(5u8), 5i8);
assert_eq!(<() as Tr>::saturating_assoc_from_u8(255u8), 127i8);
Required methods
fn saturating_cast_from(src: Src) -> Self
fn saturating_cast_from(src: Src) -> Self
Casts the value.