pub trait CarryingAdd: Sized + Add<Self> {
// Required method
fn carrying_add(
self,
rhs: Self,
carry: bool,
) -> (<Self as Add<Self>>::Output, bool);
}Expand description
Performs addition with a carry bit, for chaining multi-word additions.
Required Methods§
Sourcefn carrying_add(
self,
rhs: Self,
carry: bool,
) -> (<Self as Add<Self>>::Output, bool)
fn carrying_add( self, rhs: Self, carry: bool, ) -> (<Self as Add<Self>>::Output, bool)
Calculates self + rhs + carry and returns a tuple containing the sum
and the output carry, performing the full addition rather than
stopping at the first overflow.
For unsigned types this allows chaining together multiple additions to create a wider addition. For signed types the second tuple field signals two’s-complement overflow instead of a carry.
use const_num_traits::CarryingAdd;
// u8::MAX + 1 + carry
assert_eq!(CarryingAdd::carrying_add(u8::MAX, 1, true), (1, true));
assert_eq!(CarryingAdd::carrying_add(5u8, 2, false), (7, false));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".