[−][src]Trait az::OverflowingAs
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.
This is a convenience trait to enable writing
src.overflowing_as::<Dst>()
. This would not work with the
OverflowingCast::overflowing_cast
method because the OverflowingCast
trait is generic while the
overflowing_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 cannot be wrapped, for example when trying to cast floating-point ∞ into an integer type.
Examples
use az::OverflowingAs; assert_eq!(17i32.overflowing_as::<u8>(), (17, false)); assert_eq!((-1).overflowing_as::<u32>(), (u32::max_value(), true)); assert_eq!((17.0 + 256.0).overflowing_as::<u8>(), (17, true));
Required methods
fn overflowing_as<Dst>(self) -> (Dst, bool) where
Self: OverflowingCast<Dst>,
Self: OverflowingCast<Dst>,
Casts the value.
Implementors
impl<T> OverflowingAs for T
[src]
fn overflowing_as<Dst>(self) -> (Dst, bool) where
Self: OverflowingCast<Dst>,
[src]
Self: OverflowingCast<Dst>,