Crate saturate

Source
Expand description

This crate provides a set of traits for saturating conversion between different numeric types.

The trait SaturatingFrom is implemented by default for all standard numeric types. A blanket implementation of SaturatingInto is also provided, mirroring the standard library’s From and Into traits.

§Example

use saturate::{SaturatingFrom, SaturatingInto};

assert_eq!(0, u8::saturating_from(-26));
assert_eq!(u32::MAX, i64::MAX.saturating_into());
assert!(f32::saturating_from(u128::MAX).is_infinite()); // out of range => infinity
assert_eq!(u8::MAX, 300.0.saturating_into());

Traits§

SaturatingFrom
Trait to perform a saturating conversion between two numeric types. It is the opposite of SaturatingInto.
SaturatingInto
Trait to perform a saturating conversion between two numeric types. It is the opposite of SaturatingFrom.