Skip to main content

AbsDiff

Trait AbsDiff 

Source
pub trait AbsDiff: Sized {
    type Output;

    // Required method
    fn abs_diff(self, other: Self) -> Self::Output;
}
Expand description

Computes the absolute difference of two values.

Required Associated Types§

Source

type Output

The result type: Self for unsigned types, the unsigned counterpart for signed types (so the difference always fits).

Required Methods§

Source

fn abs_diff(self, other: Self) -> Self::Output

Computes the absolute difference between self and other without the possibility of overflow.

use const_num_traits::AbsDiff;

assert_eq!(AbsDiff::abs_diff(100u8, 120), 20);
assert_eq!(AbsDiff::abs_diff(i8::MIN, i8::MAX), 255u8);

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

Source§

type Output = u8

Source§

fn abs_diff(self, other: Self) -> u8

Source§

impl AbsDiff for i16

Source§

type Output = u16

Source§

fn abs_diff(self, other: Self) -> u16

Source§

impl AbsDiff for i32

Source§

type Output = u32

Source§

fn abs_diff(self, other: Self) -> u32

Source§

impl AbsDiff for i64

Source§

type Output = u64

Source§

fn abs_diff(self, other: Self) -> u64

Source§

impl AbsDiff for i128

Source§

type Output = u128

Source§

fn abs_diff(self, other: Self) -> u128

Source§

impl AbsDiff for isize

Source§

type Output = usize

Source§

fn abs_diff(self, other: Self) -> usize

Source§

impl AbsDiff for u8

Source§

type Output = u8

Source§

fn abs_diff(self, other: Self) -> u8

Source§

impl AbsDiff for u16

Source§

type Output = u16

Source§

fn abs_diff(self, other: Self) -> u16

Source§

impl AbsDiff for u32

Source§

type Output = u32

Source§

fn abs_diff(self, other: Self) -> u32

Source§

impl AbsDiff for u64

Source§

type Output = u64

Source§

fn abs_diff(self, other: Self) -> u64

Source§

impl AbsDiff for u128

Source§

type Output = u128

Source§

fn abs_diff(self, other: Self) -> u128

Source§

impl AbsDiff for usize

Source§

type Output = usize

Source§

fn abs_diff(self, other: Self) -> usize

Implementors§