CheckedSub

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

use core::num::traits::CheckedSub;

let result = 1_u8.checked_sub(1);
assert!(result == Option::Some(0));

let result = 1_u8.checked_sub(2);
assert!(result == Option::None); // Underflow

Fully qualified path: core::num::traits::ops::checked::CheckedSub

pub trait CheckedSub<T>

Trait functions

checked_sub

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

Fully qualified path: core::num::traits::ops::checked::CheckedSub::checked_sub

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