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
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§
Sourcefn try_add(self, rhs: Self) -> Result<Self>where
Self: CheckedAdd + Sized,
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.
Sourcefn try_sub(self, rhs: Self) -> Result<Self>where
Self: CheckedSub + Sized,
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.
Sourcefn try_mul(self, rhs: Self) -> Result<Self>where
Self: CheckedMul + Sized,
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.
Sourcefn try_div(self, rhs: Self) -> Result<Self>where
Self: CheckedDiv + Sized,
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.
Sourcefn try_rem(self, rhs: Self) -> Result<Self>where
Self: CheckedRem + Sized,
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".