CheckedAdd
Performs addition that returns None
instead of wrapping around on overflow. # Examples
use core::num::traits::CheckedAdd;
let result = 1_u8.checked_add(2);
assert!(result == Option::Some(3));
let result = 255_u8.checked_add(1);
assert!(result == Option::None); // Overflow
Fully qualified path: core::num::traits::ops::checked::CheckedAdd
pub trait CheckedAdd<T>
Trait functions
checked_add
Adds two numbers, checking for overflow. If overflow happens, None
is returned.
Fully qualified path: core::num::traits::ops::checked::CheckedAdd::checked_add
fn checked_add(self: T, v: T) -> Option<T>