None instead of wrapping around on
overflow.
Signature
Examples
Trait functions
checked_add
Adds two numbers, checking for overflow. If overflow happens,None is
returned.
None instead of wrapping around on
overflow.
pub trait CheckedAdd
use core::num::traits::CheckedAdd;
let result = 1_u8.checked_add(2);
assert!(result == Some(3));
let result = 255_u8.checked_add(1);
assert!(result == None); // Overflow
None is
returned.
fn checked_add(self: T, v: T) -> Option
Was this page helpful?