Skip to main content

CheckedAbs

Trait CheckedAbs 

Source
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§

Source

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".

Implementations on Foreign Types§

Source§

impl CheckedAbs for i8

Source§

impl CheckedAbs for i16

Source§

impl CheckedAbs for i32

Source§

impl CheckedAbs for i64

Source§

impl CheckedAbs for i128

Source§

impl CheckedAbs for isize

Implementors§