[][src]Trait az::SaturatingAs

pub trait SaturatingAs {
    fn saturating_as<Dst>(self) -> Dst
    where
        Self: SaturatingCast<Dst>
; }

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

This is a convenience trait to enable writing src.saturating_as::<Dst>(). This would not work with the SaturatingCast::saturating_cast method because the SaturatingCast trait is generic while the saturating_cast method is not generic.

This trait’s method is suitable for chaining.

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::SaturatingAs;
assert_eq!((-1).saturating_as::<u32>(), 0);
assert_eq!((17.0 + 256.0).saturating_as::<u8>(), 255);

Required methods

fn saturating_as<Dst>(self) -> Dst where
    Self: SaturatingCast<Dst>, 

Casts the value.

Loading content...

Implementors

impl<T> SaturatingAs for T[src]

Loading content...