pub trait Expected {
// Provided methods
fn expected_add(self, rhs: Self) -> Self
where Self: CheckedAdd + Sized { ... }
fn expected_sub(self, rhs: Self) -> Self
where Self: CheckedSub + Sized { ... }
fn expected_mul(self, rhs: Self) -> Self
where Self: CheckedMul + Sized { ... }
fn expected_div(self, rhs: Self) -> Self
where Self: CheckedDiv + Sized { ... }
fn expected_rem(self, rhs: Self) -> Self
where Self: CheckedRem + Sized { ... }
}Expand description
Provides checked arithmetic for operations expected to succeed.
Each method delegates to the corresponding Checked* trait. A failed check
is treated as a violated program invariant and panics.
Provided Methods§
Sourcefn expected_add(self, rhs: Self) -> Selfwhere
Self: CheckedAdd + Sized,
fn expected_add(self, rhs: Self) -> Selfwhere
Self: CheckedAdd + Sized,
Adds rhs with an expectation that the operation is valid.
A successful checked addition returns its value unchanged.
§Panics
Panics when the underlying CheckedAdd operation returns None.
Sourcefn expected_sub(self, rhs: Self) -> Selfwhere
Self: CheckedSub + Sized,
fn expected_sub(self, rhs: Self) -> Selfwhere
Self: CheckedSub + Sized,
Subtracts rhs with an expectation that the operation is valid.
A successful checked subtraction returns its value unchanged.
§Panics
Panics when the underlying CheckedSub operation returns None.
Sourcefn expected_mul(self, rhs: Self) -> Selfwhere
Self: CheckedMul + Sized,
fn expected_mul(self, rhs: Self) -> Selfwhere
Self: CheckedMul + Sized,
Multiplies by rhs with an expectation that the operation is valid.
A successful checked multiplication returns its value unchanged.
§Panics
Panics when the underlying CheckedMul operation returns None.
Sourcefn expected_div(self, rhs: Self) -> Selfwhere
Self: CheckedDiv + Sized,
fn expected_div(self, rhs: Self) -> Selfwhere
Self: CheckedDiv + Sized,
Divides by rhs with an expectation that the operation is valid.
A successful checked division returns its value unchanged.
§Panics
Panics when the underlying CheckedDiv operation returns None.
Sourcefn expected_rem(self, rhs: Self) -> Selfwhere
Self: CheckedRem + Sized,
fn expected_rem(self, rhs: Self) -> Selfwhere
Self: CheckedRem + Sized,
Computes the remainder with an expectation that the operation is valid.
A successful checked remainder returns its value unchanged.
§Panics
Panics when the underlying CheckedRem operation returns None.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".