Trait rotary_add::RotaryAdd

source ·
pub trait RotaryAdd<T: Add<Output = T> + Sub<Output = T> + PartialEq + Copy> {
    // Required methods
    fn rotary_add(&self, other: &T) -> T;
    fn rotary_sub(&self, other: &T) -> T;
}
Expand description

RotaryAdd works on the whole range of the unsigned integer Trait with methods for cyclical or rotary arithmetic with unsigned integers When additions or subtractions may otherwise overflow, either falling below zero or above the type’s maximum, the values rotate. This is mainly for use with cryptography

Required Methods§

source

fn rotary_add(&self, other: &T) -> T

Add another unsigned integer and start from zero again should value overflow, but retaining the remainder With u8, 255.rotary_add(4) is thus 3

source

fn rotary_sub(&self, other: &T) -> T

Subtract another unsigned integer and start from the type’s max value if the target result may be otherwise be negative if it were a signed integer e.g. with u8 the max is 255 (allowing for 256 values including zero) 3.rotary_sub(4) is thus 255

Implementations on Foreign Types§

source§

impl RotaryAdd<u8> for u8

source§

fn rotary_add(&self, other: &u8) -> u8

source§

fn rotary_sub(&self, other: &u8) -> u8

source§

impl RotaryAdd<u16> for u16

source§

fn rotary_add(&self, other: &u16) -> u16

source§

fn rotary_sub(&self, other: &u16) -> u16

source§

impl RotaryAdd<u32> for u32

source§

fn rotary_add(&self, other: &u32) -> u32

source§

fn rotary_sub(&self, other: &u32) -> u32

Implementors§