pub trait SaturatingCastFrom<Src> {
// Required method
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§
sourcefn saturating_cast_from(src: Src) -> Self
fn saturating_cast_from(src: Src) -> Self
Casts the value.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.