Function az::saturating_cast

source ·
pub fn saturating_cast<Src: SaturatingCast<Dst>, Dst>(src: Src) -> Dst
Expand description

Casts the value, saturating if the value does not fit.

§Panics

Panics if the value does not fit and saturation does not make sense, for example when trying to cast floating-point NaN into an integer type.

§Examples

assert_eq!(az::saturating_cast::<i32, u32>(-1), 0);
assert_eq!(az::saturating_cast::<f32, u8>(17.0 + 256.0), 255);