Skip to main content

CheckedAdd

Trait CheckedAdd 

Source
pub trait CheckedAdd<Other = Self> {
    type Output;

    // Required method
    fn checked_add(self, other: Other) -> Self::Output;
}

Required Associated Types§

Required Methods§

Source

fn checked_add(self, other: Other) -> Self::Output

Returns checked addition.

use traiter::numbers::CheckedAdd;
// signed integers
assert_eq!(CheckedAdd::checked_add(i8::MIN, -1i8), None);
assert_eq!(CheckedAdd::checked_add(0i8, 1i8), Some(1i8));
assert_eq!(CheckedAdd::checked_add(i8::MAX, 1i8), None);
// unsigned integers
assert_eq!(CheckedAdd::checked_add(0u8, 1u8), Some(1u8));
assert_eq!(CheckedAdd::checked_add(1u8, 1u8), Some(2u8));
assert_eq!(CheckedAdd::checked_add(u8::MAX, 1u8), None);

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl CheckedAdd for i8

Source§

type Output = Option<i8>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for i16

Source§

type Output = Option<i16>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for i32

Source§

type Output = Option<i32>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for i64

Source§

type Output = Option<i64>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for i128

Source§

type Output = Option<i128>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for isize

Source§

type Output = Option<isize>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for u8

Source§

type Output = Option<u8>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for u16

Source§

type Output = Option<u16>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for u32

Source§

type Output = Option<u32>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for u64

Source§

type Output = Option<u64>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for u128

Source§

type Output = Option<u128>

Source§

fn checked_add(self, other: Self) -> Self::Output

Source§

impl CheckedAdd for usize

Source§

type Output = Option<usize>

Source§

fn checked_add(self, other: Self) -> Self::Output

Implementors§