Function az::overflowing_cast

source ·
pub fn overflowing_cast<Src: OverflowingCast<Dst>, Dst>(src: Src) -> (Dst, bool)
Expand description

Overflowing cast.

Returns a tuple of the value and a bool, indicating whether an overflow has occurred. On overflow, the wrapped value is returned.

§Panics

Panics if the value does not fit and cannot be wrapped, for example when trying to cast floating-point ∞ into an integer type.

§Examples

assert_eq!(az::overflowing_cast::<i32, u32>(-1), (u32::max_value(), true));
assert_eq!(az::overflowing_cast::<f32, u8>(17.0 + 256.0), (17, true));