Trait CheckedAdd

Source
pub trait CheckedAdd: Add + Sized {
    // Required method
    fn checked_add(self, rhs: Self) -> Option<Self>;
}
Expand description

Performs checked addition. Maps directly to the integers checked_add method. (i.e. u8::checked_add) Consult the docs of the primitive methods to learn more.

Required Methods§

Source

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

performs checked add

§Example
let a = 1u8;
let b = 2u8;
 
assert_eq!(CheckedAdd::checked_add(a, b), a.checked_add(b));
let b = u8::MAX;
assert_eq!(CheckedAdd::checked_add(a, b), a.checked_add(b));

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 CheckedAdd for i8

Source§

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

Source§

impl CheckedAdd for i16

Source§

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

Source§

impl CheckedAdd for i32

Source§

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

Source§

impl CheckedAdd for i64

Source§

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

Source§

impl CheckedAdd for u8

Source§

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

Source§

impl CheckedAdd for u16

Source§

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

Source§

impl CheckedAdd for u32

Source§

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

Source§

impl CheckedAdd for u64

Source§

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

Implementors§