Skip to main content

CheckedAddSigned

Trait CheckedAddSigned 

Source
pub trait CheckedAddSigned: Sized {
    type Signed;
    type Output;

    // Required method
    fn checked_add_signed(self, rhs: Self::Signed) -> Option<Self::Output>;
}
Expand description

Checked addition of a signed value to an unsigned value.

Required Associated Types§

Source

type Signed

The counterpart type of opposite signedness.

Source

type Output

The (owned) result type.

Required Methods§

Source

fn checked_add_signed(self, rhs: Self::Signed) -> Option<Self::Output>

Computes self + rhs, returning None if overflow occurred.

use const_num_traits::CheckedAddSigned;

assert_eq!(CheckedAddSigned::checked_add_signed(1u8, 2), Some(3));
assert_eq!(CheckedAddSigned::checked_add_signed(1u8, -2), None);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl CheckedAddSigned for u8

Source§

impl CheckedAddSigned for u16

Source§

impl CheckedAddSigned for u32

Source§

impl CheckedAddSigned for u64

Source§

impl CheckedAddSigned for u128

Source§

impl CheckedAddSigned for usize

Implementors§