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
impl CheckedSub for BigUint
impl CheckedSub for BigInt
impl CheckedSub for uint
impl CheckedSub for u8
impl CheckedSub for u16
impl CheckedSub for u32
impl CheckedSub for u64
impl CheckedSub for int
impl CheckedSub for i8
impl CheckedSub for i16
impl CheckedSub for i32
impl CheckedSub for i64