pub trait SaturatingCast<Dst> {
    fn saturating_cast(self) -> Dst;
}
Expand description

Used to cast into the destination type, saturating if the value does not fit.

It is normally easier to use the SaturatingAs trait instead of this trait.

Panics

This trait’s method 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

use az::SaturatingCast;
let a: u32 = (-1).saturating_cast();
assert_eq!(a, 0);
assert_eq!(SaturatingCast::<u8>::saturating_cast(17.0 + 256.0), 255);

Required methods

Casts the value.

Implementations on Foreign Types

Implementors