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

pub trait CheckedSub: Sub<Self, Self> {
    fn checked_sub(&self, v: &Self) -> Option<Self>;
}

Performs subtraction that returns None instead of wrapping around on underflow.

Required Methods

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

Subtracts two numbers, checking for underflow. If underflow happens, None is returned.

Example

extern crate num; fn main() { use num::CheckedSub; assert_eq!((-127i8).checked_sub(&1), Some(-128)); assert_eq!((-128i8).checked_sub(&1), None); }
use num::CheckedSub;
assert_eq!((-127i8).checked_sub(&1), Some(-128));
assert_eq!((-128i8).checked_sub(&1), None);

Implementors