Skip to main content

Expected

Trait Expected 

Source
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

Adds checked arithmetic methods that panic on failure.

Each operation panics when its underlying checked operation fails. The trait covers addition, subtraction, multiplication, division, and remainder. 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§

Source

fn expected_add(self, rhs: Self) -> Self
where 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.

Source

fn expected_sub(self, rhs: Self) -> Self
where 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.

Source

fn expected_mul(self, rhs: Self) -> Self
where 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.

Source

fn expected_div(self, rhs: Self) -> Self
where 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.

Source

fn expected_rem(self, rhs: Self) -> Self
where 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".

Implementors§

Source§

impl<T> Expected for T