Trait az::OverflowingCast
source · pub trait OverflowingCast<Dst> {
// Required method
fn overflowing_cast(self) -> (Dst, bool);
}
Expand description
Used for overflowing casts.
This trait’s method returns a [tuple] of the value and a [bool
],
indicating whether an overflow has occurred. On overflow, the wrapped
value is returned.
It is normally easier to use the OverflowingAs
trait instead of this trait.
§Examples
use az::OverflowingCast;
let a: (u8, bool) = 17i32.overflowing_cast();
assert_eq!(a, (17, false));
assert_eq!(OverflowingCast::<u32>::overflowing_cast(-1), (u32::max_value(), true));
assert_eq!(OverflowingCast::<u8>::overflowing_cast(17.0 + 256.0), (17, true));
§Panics
This trait’s method panics if the value does not fit and cannot be wrapped, for example when trying to cast floating-point ∞ into an integer type.
Required Methods§
sourcefn overflowing_cast(self) -> (Dst, bool)
fn overflowing_cast(self) -> (Dst, bool)
Casts the value.