pub trait CheckedAbs: Sized + Neg {
// Required method
fn checked_abs(self) -> Option<<Self as Neg>::Output>;
}Expand description
Computes the absolute value, returning None if it can’t be represented.
Required Methods§
Sourcefn checked_abs(self) -> Option<<Self as Neg>::Output>
fn checked_abs(self) -> Option<<Self as Neg>::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".