pub trait CheckedAbs: Sized {
type Output;
// Required method
fn checked_abs(self) -> Option<Self::Output>;
}Expand description
Computes the absolute value, returning None if it can’t be represented.
Required Associated Types§
Required Methods§
Sourcefn checked_abs(self) -> Option<Self::Output>
fn checked_abs(self) -> Option<Self::Output>
Checked absolute value. Computes self.abs(), returning None if
self == MIN (the result can’t be represented).
§Examples
use const_num_traits::CheckedAbs;
assert_eq!(CheckedAbs::checked_abs(-5i32), Some(5));
assert_eq!(CheckedAbs::checked_abs(i32::MIN), None);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".