Skip to main content

WrappingArithmetic

Trait WrappingArithmetic 

Source
pub trait WrappingArithmetic:
    WrappingAdd
    + WrappingSub
    + WrappingMul
    + WrappingNeg
    + WrappingShl
    + WrappingShr { }
Expand description

A composite trait for wrapping arithmetic operations.

Combines all wrapping arithmetic traits from num-traits: WrappingAdd, WrappingSub, WrappingMul, WrappingNeg, WrappingShl, and WrappingShr.

Implemented for all primitive integer types.

§Examples

use platform_num::WrappingArithmetic;

fn wrapping_increment<T: WrappingArithmetic>(a: &T, b: &T) -> T {
    a.wrapping_add(b)
}

assert_eq!(wrapping_increment(&u8::MAX, &1u8), 0u8);

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.

Implementors§