ArithmeticTryOps

Trait ArithmeticTryOps 

Source
pub trait ArithmeticTryOps<RHS = Self>
where Self: Sized + Display + Debug + TypeName, RHS: Sized + Display + Debug,
{ // Required methods fn try_add(self, other: RHS) -> Result<Self, OverflowError<Self, RHS>>; fn try_sub(self, other: RHS) -> Result<Self, OverflowError<Self, RHS>>; fn try_mul(self, other: RHS) -> Result<Self, OverflowError<Self, RHS>>; fn try_div(self, other: RHS) -> Result<Self, DivisionByZeroError<Self>>; fn try_div_euclid( self, other: RHS, ) -> Result<Self, DivisionByZeroError<Self>>; fn try_rem(self, other: RHS) -> Result<Self, DivisionByZeroError<Self>>; fn try_rem_euclid( self, other: RHS, ) -> Result<Self, DivisionByZeroError<Self>>; fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>; fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>; fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>; }
Expand description

Adds arithmetic operations similar to checked_* but returning Result with nice errors

Required Methods§

Source

fn try_add(self, other: RHS) -> Result<Self, OverflowError<Self, RHS>>

Source

fn try_sub(self, other: RHS) -> Result<Self, OverflowError<Self, RHS>>

Source

fn try_mul(self, other: RHS) -> Result<Self, OverflowError<Self, RHS>>

Source

fn try_div(self, other: RHS) -> Result<Self, DivisionByZeroError<Self>>

Source

fn try_div_euclid(self, other: RHS) -> Result<Self, DivisionByZeroError<Self>>

Source

fn try_rem(self, other: RHS) -> Result<Self, DivisionByZeroError<Self>>

Source

fn try_rem_euclid(self, other: RHS) -> Result<Self, DivisionByZeroError<Self>>

Source

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

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.

Implementations on Foreign Types§

Source§

impl ArithmeticTryOps for i8

Source§

fn try_add(self, other: i8) -> Result<Self, OverflowError<Self, i8>>

Source§

fn try_sub(self, other: i8) -> Result<Self, OverflowError<Self, i8>>

Source§

fn try_mul(self, other: i8) -> Result<Self, OverflowError<Self, i8>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for i16

Source§

fn try_add(self, other: i16) -> Result<Self, OverflowError<Self, i16>>

Source§

fn try_sub(self, other: i16) -> Result<Self, OverflowError<Self, i16>>

Source§

fn try_mul(self, other: i16) -> Result<Self, OverflowError<Self, i16>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for i32

Source§

fn try_add(self, other: i32) -> Result<Self, OverflowError<Self, i32>>

Source§

fn try_sub(self, other: i32) -> Result<Self, OverflowError<Self, i32>>

Source§

fn try_mul(self, other: i32) -> Result<Self, OverflowError<Self, i32>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for i64

Source§

fn try_add(self, other: i64) -> Result<Self, OverflowError<Self, i64>>

Source§

fn try_sub(self, other: i64) -> Result<Self, OverflowError<Self, i64>>

Source§

fn try_mul(self, other: i64) -> Result<Self, OverflowError<Self, i64>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for i128

Source§

fn try_add(self, other: i128) -> Result<Self, OverflowError<Self, i128>>

Source§

fn try_sub(self, other: i128) -> Result<Self, OverflowError<Self, i128>>

Source§

fn try_mul(self, other: i128) -> Result<Self, OverflowError<Self, i128>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for isize

Source§

fn try_add(self, other: isize) -> Result<Self, OverflowError<Self, isize>>

Source§

fn try_sub(self, other: isize) -> Result<Self, OverflowError<Self, isize>>

Source§

fn try_mul(self, other: isize) -> Result<Self, OverflowError<Self, isize>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for u8

Source§

fn try_add(self, other: u8) -> Result<Self, OverflowError<Self, u8>>

Source§

fn try_sub(self, other: u8) -> Result<Self, OverflowError<Self, u8>>

Source§

fn try_mul(self, other: u8) -> Result<Self, OverflowError<Self, u8>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for u16

Source§

fn try_add(self, other: u16) -> Result<Self, OverflowError<Self, u16>>

Source§

fn try_sub(self, other: u16) -> Result<Self, OverflowError<Self, u16>>

Source§

fn try_mul(self, other: u16) -> Result<Self, OverflowError<Self, u16>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for u32

Source§

fn try_add(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_sub(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_mul(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for u64

Source§

fn try_add(self, other: u64) -> Result<Self, OverflowError<Self, u64>>

Source§

fn try_sub(self, other: u64) -> Result<Self, OverflowError<Self, u64>>

Source§

fn try_mul(self, other: u64) -> Result<Self, OverflowError<Self, u64>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for u128

Source§

fn try_add(self, other: u128) -> Result<Self, OverflowError<Self, u128>>

Source§

fn try_sub(self, other: u128) -> Result<Self, OverflowError<Self, u128>>

Source§

fn try_mul(self, other: u128) -> Result<Self, OverflowError<Self, u128>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

impl ArithmeticTryOps for usize

Source§

fn try_add(self, other: usize) -> Result<Self, OverflowError<Self, usize>>

Source§

fn try_sub(self, other: usize) -> Result<Self, OverflowError<Self, usize>>

Source§

fn try_mul(self, other: usize) -> Result<Self, OverflowError<Self, usize>>

Source§

fn try_pow(self, other: u32) -> Result<Self, OverflowError<Self, u32>>

Source§

fn try_div(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_div_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_rem_euclid(self, other: Self) -> Result<Self, DivisionByZeroError<Self>>

Source§

fn try_shl(self, other: u32) -> Result<Self, BigShiftError<Self>>

Source§

fn try_shr(self, other: u32) -> Result<Self, BigShiftError<Self>>

Implementors§