SafeMathOps

Trait SafeMathOps 

Source
pub trait SafeMathOps: Copy {
    // Required methods
    fn safe_add(self, rhs: Self) -> Result<Self, SafeMathError>;
    fn safe_sub(self, rhs: Self) -> Result<Self, SafeMathError>;
    fn safe_mul(self, rhs: Self) -> Result<Self, SafeMathError>;
    fn safe_div(self, rhs: Self) -> Result<Self, SafeMathError>;
    fn safe_rem(self, rhs: Self) -> Result<Self, SafeMathError>;
}
Expand description

Unified trait providing all safe arithmetic operations.

This trait combines all individual safe operation traits for convenience. Types implementing this trait can perform all basic arithmetic operations with overflow/underflow and division-by-zero protection.

Required Methods§

Source

fn safe_add(self, rhs: Self) -> Result<Self, SafeMathError>

Safe addition with overflow checking.

Source

fn safe_sub(self, rhs: Self) -> Result<Self, SafeMathError>

Safe subtraction with underflow checking.

Source

fn safe_mul(self, rhs: Self) -> Result<Self, SafeMathError>

Safe multiplication with overflow checking.

Source

fn safe_div(self, rhs: Self) -> Result<Self, SafeMathError>

Safe division with division-by-zero checking.

Source

fn safe_rem(self, rhs: Self) -> Result<Self, SafeMathError>

Safe remainder with division-by-zero checking.

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§

Source§

impl<T> SafeMathOps for T