Skip to main content

UnsignedAbs

Trait UnsignedAbs 

Source
pub trait UnsignedAbs: Sized {
    type Unsigned;

    // Required method
    fn unsigned_abs(self) -> Self::Unsigned;
}
Expand description

Computes the absolute value as the unsigned counterpart type, which cannot overflow (unlike abs, which overflows on MIN).

Required Associated Types§

Source

type Unsigned

The unsigned counterpart type (e.g. u32 for i32).

Required Methods§

Source

fn unsigned_abs(self) -> Self::Unsigned

Computes the absolute value of self without any wrapping or panicking.

use const_num_traits::UnsignedAbs;

assert_eq!(UnsignedAbs::unsigned_abs(-100i8), 100u8);
assert_eq!(UnsignedAbs::unsigned_abs(i8::MIN), 128u8);

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 UnsignedAbs for i8

Source§

impl UnsignedAbs for i16

Source§

impl UnsignedAbs for i32

Source§

impl UnsignedAbs for i64

Source§

impl UnsignedAbs for i128

Source§

impl UnsignedAbs for isize

Implementors§