Skip to main content

ConstAbsDiff

Trait ConstAbsDiff 

Source
pub trait ConstAbsDiff:
    Sized
    + Ord
    + Sub<Output = Self> {
    // Required method
    fn abs_diff(self, other: Self) -> Self;
}
Expand description

Const-compatible absolute difference.

Computes the absolute difference between two values. For unsigned types, this is max(a, b) - min(a, b).

§Unsigned types only

This trait is designed for unsigned integer types where abs_diff cannot overflow. Implementors for signed types must ensure overflow is handled correctly (e.g., by returning an unsigned result type or using checked arithmetic), as the trait bounds do not enforce this.

Required Methods§

Source

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

Computes the absolute difference between self and other.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ConstAbsDiff for u8

Source§

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

Source§

impl ConstAbsDiff for u16

Source§

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

Source§

impl ConstAbsDiff for u32

Source§

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

Source§

impl ConstAbsDiff for u64

Source§

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

Source§

impl ConstAbsDiff for u128

Source§

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

Implementors§

Source§

impl<T: ConstMachineWord + MachineWord, const N: usize> ConstAbsDiff for FixedUInt<T, N>