Skip to main content

Tried

Trait Tried 

Source
pub trait Tried {
    // Provided methods
    fn try_add(self, rhs: Self) -> Result<Self>
       where Self: CheckedAdd + Sized { ... }
    fn try_sub(self, rhs: Self) -> Result<Self>
       where Self: CheckedSub + Sized { ... }
    fn try_mul(self, rhs: Self) -> Result<Self>
       where Self: CheckedMul + Sized { ... }
    fn try_div(self, rhs: Self) -> Result<Self>
       where Self: CheckedDiv + Sized { ... }
    fn try_rem(self, rhs: Self) -> Result<Self>
       where Self: CheckedRem + Sized { ... }
}
Expand description

Adds checked arithmetic methods that return a Result.

Each operation returns Error::Arithmetic when its checked operation fails. The trait covers addition, subtraction, multiplication, division, and remainder. Provides checked arithmetic that reports overflow and invalid operations.

Each method delegates to the corresponding Checked* trait. A successful operation returns its value through the crate’s result type.

Provided Methods§

Source

fn try_add(self, rhs: Self) -> Result<Self>
where Self: CheckedAdd + Sized,

Adds rhs with checked arithmetic.

Values that the underlying CheckedAdd implementation accepts are returned unchanged. Overflow is represented by the crate’s arithmetic error.

Source

fn try_sub(self, rhs: Self) -> Result<Self>
where Self: CheckedSub + Sized,

Subtracts rhs with checked arithmetic.

Values that the underlying CheckedSub implementation accepts are returned unchanged. Overflow is represented by the crate’s arithmetic error.

Source

fn try_mul(self, rhs: Self) -> Result<Self>
where Self: CheckedMul + Sized,

Multiplies by rhs with checked arithmetic.

Values that the underlying CheckedMul implementation accepts are returned unchanged. Overflow is represented by the crate’s arithmetic error.

Source

fn try_div(self, rhs: Self) -> Result<Self>
where Self: CheckedDiv + Sized,

Divides by rhs with checked arithmetic.

Values that the underlying CheckedDiv implementation accepts are returned unchanged. Division by zero or overflow becomes the crate’s arithmetic error.

Source

fn try_rem(self, rhs: Self) -> Result<Self>
where Self: CheckedRem + Sized,

Computes the remainder by rhs with checked arithmetic.

Values that the underlying CheckedRem implementation accepts are returned unchanged. A failed checked remainder, including a zero divisor or overflow, becomes the crate’s arithmetic error.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> Tried for T