Skip to main content

CtCheckedAdd

Trait CtCheckedAdd 

Source
pub trait CtCheckedAdd: Sized {
    // Required method
    fn ct_checked_add(&self, v: &Self) -> CtOption<Self>;
}
Available on crate feature ct only.
Expand description

Constant-time checked addition (the masked counterpart of CheckedAdd).

Required Methods§

Source

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Computes self + v, returning a CtOption that is None-masked on overflow.

use const_num_traits::ops::ct::CtCheckedAdd;

assert_eq!(250u8.ct_checked_add(&5).unwrap(), 255);
assert!(bool::from(255u8.ct_checked_add(&1).is_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 CtCheckedAdd for i8

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for i16

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for i32

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for i64

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for i128

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for isize

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for u8

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for u16

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for u32

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for u64

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for u128

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Source§

impl CtCheckedAdd for usize

Source§

fn ct_checked_add(&self, v: &Self) -> CtOption<Self>

Implementors§