Skip to main content

CheckedArithmetic

Trait CheckedArithmetic 

pub trait CheckedArithmetic: Sized + Sealed {
    // Required methods
    fn checked_add(self, rhs: Self) -> Option<Self>;
    fn checked_sub(self, rhs: Self) -> Option<Self>;
    fn checked_mul(self, rhs: Self) -> Option<Self>;
}
Expand description

Primitive integer types supported by the checked arithmetic wrappers.

Required Methods§

fn checked_add(self, rhs: Self) -> Option<Self>

Returns self + rhs, or None on overflow.

fn checked_sub(self, rhs: Self) -> Option<Self>

Returns self - rhs, or None on overflow.

fn checked_mul(self, rhs: Self) -> Option<Self>

Returns self * rhs, or None on overflow.

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§

§

impl CheckedArithmetic for i8

§

fn checked_add(self, rhs: i8) -> Option<i8>

§

fn checked_sub(self, rhs: i8) -> Option<i8>

§

fn checked_mul(self, rhs: i8) -> Option<i8>

§

impl CheckedArithmetic for i16

§

fn checked_add(self, rhs: i16) -> Option<i16>

§

fn checked_sub(self, rhs: i16) -> Option<i16>

§

fn checked_mul(self, rhs: i16) -> Option<i16>

§

impl CheckedArithmetic for i32

§

fn checked_add(self, rhs: i32) -> Option<i32>

§

fn checked_sub(self, rhs: i32) -> Option<i32>

§

fn checked_mul(self, rhs: i32) -> Option<i32>

§

impl CheckedArithmetic for i64

§

fn checked_add(self, rhs: i64) -> Option<i64>

§

fn checked_sub(self, rhs: i64) -> Option<i64>

§

fn checked_mul(self, rhs: i64) -> Option<i64>

§

impl CheckedArithmetic for i128

§

fn checked_add(self, rhs: i128) -> Option<i128>

§

fn checked_sub(self, rhs: i128) -> Option<i128>

§

fn checked_mul(self, rhs: i128) -> Option<i128>

§

impl CheckedArithmetic for isize

§

fn checked_add(self, rhs: isize) -> Option<isize>

§

fn checked_sub(self, rhs: isize) -> Option<isize>

§

fn checked_mul(self, rhs: isize) -> Option<isize>

§

impl CheckedArithmetic for u8

§

fn checked_add(self, rhs: u8) -> Option<u8>

§

fn checked_sub(self, rhs: u8) -> Option<u8>

§

fn checked_mul(self, rhs: u8) -> Option<u8>

§

impl CheckedArithmetic for u16

§

fn checked_add(self, rhs: u16) -> Option<u16>

§

fn checked_sub(self, rhs: u16) -> Option<u16>

§

fn checked_mul(self, rhs: u16) -> Option<u16>

§

impl CheckedArithmetic for u32

§

fn checked_add(self, rhs: u32) -> Option<u32>

§

fn checked_sub(self, rhs: u32) -> Option<u32>

§

fn checked_mul(self, rhs: u32) -> Option<u32>

§

impl CheckedArithmetic for u64

§

fn checked_add(self, rhs: u64) -> Option<u64>

§

fn checked_sub(self, rhs: u64) -> Option<u64>

§

fn checked_mul(self, rhs: u64) -> Option<u64>

§

impl CheckedArithmetic for u128

§

fn checked_add(self, rhs: u128) -> Option<u128>

§

fn checked_sub(self, rhs: u128) -> Option<u128>

§

fn checked_mul(self, rhs: u128) -> Option<u128>

§

impl CheckedArithmetic for usize

§

fn checked_add(self, rhs: usize) -> Option<usize>

§

fn checked_sub(self, rhs: usize) -> Option<usize>

§

fn checked_mul(self, rhs: usize) -> Option<usize>

Implementors§