Trait num::traits::CheckedAddExperimental [-]  [+] [src]

pub trait CheckedAdd: Add<Self, Self> {
    fn checked_add(&self, v: &Self) -> Option<Self>;
}

Performs addition that returns None instead of wrapping around on overflow.

Required Methods

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

Adds two numbers, checking for overflow. If overflow happens, None is returned.

Example

extern crate num; fn main() { use num::CheckedAdd; assert_eq!(5u16.checked_add(&65530), Some(65535)); assert_eq!(6u16.checked_add(&65530), None); }
use num::CheckedAdd;
assert_eq!(5u16.checked_add(&65530), Some(65535));
assert_eq!(6u16.checked_add(&65530), None);

Implementors