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§
Sourcefn safe_add(self, rhs: Self) -> Result<Self, SafeMathError>
fn safe_add(self, rhs: Self) -> Result<Self, SafeMathError>
Safe addition with overflow checking.
Sourcefn safe_sub(self, rhs: Self) -> Result<Self, SafeMathError>
fn safe_sub(self, rhs: Self) -> Result<Self, SafeMathError>
Safe subtraction with underflow checking.
Sourcefn safe_mul(self, rhs: Self) -> Result<Self, SafeMathError>
fn safe_mul(self, rhs: Self) -> Result<Self, SafeMathError>
Safe multiplication with overflow checking.
Sourcefn safe_div(self, rhs: Self) -> Result<Self, SafeMathError>
fn safe_div(self, rhs: Self) -> Result<Self, SafeMathError>
Safe division with division-by-zero checking.
Sourcefn safe_rem(self, rhs: Self) -> Result<Self, SafeMathError>
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.