Skip to main content

CheckedArithmetic

Trait CheckedArithmetic 

Source
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§

Source

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

Returns self + rhs, or None on overflow.

Source

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

Returns self - rhs, or None on overflow.

Source

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§

Source§

impl CheckedArithmetic for i8

Source§

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

Source§

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

Source§

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

Source§

impl CheckedArithmetic for i16

Source§

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

Source§

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

Source§

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

Source§

impl CheckedArithmetic for i32

Source§

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

Source§

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

Source§

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

Source§

impl CheckedArithmetic for i64

Source§

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

Source§

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

Source§

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

Source§

impl CheckedArithmetic for i128

Source§

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

Source§

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

Source§

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

Source§

impl CheckedArithmetic for isize

Source§

impl CheckedArithmetic for u8

Source§

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

Source§

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

Source§

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

Source§

impl CheckedArithmetic for u16

Source§

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

Source§

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

Source§

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

Source§

impl CheckedArithmetic for u32

Source§

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

Source§

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

Source§

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

Source§

impl CheckedArithmetic for u64

Source§

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

Source§

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

Source§

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

Source§

impl CheckedArithmetic for u128

Source§

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

Source§

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

Source§

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

Source§

impl CheckedArithmetic for usize

Implementors§