Skip to main content

Magnitude

Trait Magnitude 

Source
pub trait Magnitude:
    Copy
    + PartialEq
    + PartialOrd {
    const ZERO: Self;

    // Required methods
    fn abs_diff(self, other: Self) -> Self;
    fn checked_add(self, other: Self) -> Option<Self>;
    fn checked_sub(self, other: Self) -> Option<Self>;

    // Provided method
    fn is_zero(self) -> bool { ... }
}
Expand description

Trait for unsigned numeric types supporting arithmetic operations.

This trait defines the core operations needed for currency magnitude types like Amount and Fee.

Required Associated Constants§

Source

const ZERO: Self

The zero value for this type.

Required Methods§

Source

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

Returns the absolute difference between self and other.

Source

fn checked_add(self, other: Self) -> Option<Self>

Checked addition. Returns None if overflow occurred.

Source

fn checked_sub(self, other: Self) -> Option<Self>

Checked subtraction. Returns None if underflow occurred.

Provided Methods§

Source

fn is_zero(self) -> bool

Returns true if this value is zero.

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.

Implementors§