pub trait CheckedAdd: Add + Sized {
// Required method
fn checked_add(self, rhs: Self) -> Option<Self>;
}
Expand description
Performs checked addition. Maps directly to the integers checked_add method. (i.e.
u8::checked_add
) Consult the docs of the primitive methods to learn more.
Required Methods§
Sourcefn checked_add(self, rhs: Self) -> Option<Self>
fn checked_add(self, rhs: Self) -> Option<Self>
performs checked add
§Example
let a = 1u8;
let b = 2u8;
assert_eq!(CheckedAdd::checked_add(a, b), a.checked_add(b));
let b = u8::MAX;
assert_eq!(CheckedAdd::checked_add(a, b), a.checked_add(b));
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.