Trait rotary_add::CycleAdd

source ·
pub trait CycleAdd<T: Add<Output = T> + Sub<Output = T> + PartialEq + Copy> {
    // Required methods
    fn cycle_add(&self, other: &T, base: T) -> T;
    fn cycle_sub(&self, other: &T, base: T) -> T;
    fn series_add(&self, other: &T, limit: T) -> T;
    fn series_sub(&self, other: &T, limit: T) -> T;
    fn series_mod(&self, limit: T) -> T;
}
Expand description

CycleAdd works on range from 0 to a a specified base. The max value is 1 less than the base Trait with methods for cyclical arithmetic with unsigned integers Values rotate within a range of zero to 1 below the specified base, when normal addition or subtraction would yield out-of-range values

Required Methods§

source

fn cycle_add(&self, other: &T, base: T) -> T

Add another unsigned integer and start from zero again if the result is out of range. With a a base of 60 applied to a u8 value, 53.cycle_add(10, 60) is thus 3

source

fn cycle_sub(&self, other: &T, base: T) -> T

Subtract another unsigned integer and start from a specified base if the target result may be otherwise be negative if it were a signed integer e.g. if a base of 24 is applied to a u8 value, its max is 23 3.cycle_sub(4) is thus 23

source

fn series_add(&self, other: &T, limit: T) -> T

Add another unsigned integer representing a number in a series from 1 to specified maximum Unlike cycle_add the max value is the limit and the minimum value is 1. Hence 1.series_add(7, 1) will be 1

source

fn series_sub(&self, other: &T, limit: T) -> T

Subtract another unsigned integer representing a number in a series from 1 to specified maximum Unlike cycle_sub the max value is the limit and the minimum value is 1. Hence 1.series_sub(1, 7) will be 7

source

fn series_mod(&self, limit: T) -> T

Find the remainder in a range between one and a limit. This methods normalises an unsigned integer within a series
from 1 to specified limit Unlike % or T.mod(T) 0.series_mod(&T) will equal the limit as results cannot be lower than 1 This is mainly used for arbitrary series like weekday numbers 1 to 7 or month numbers 1 to 31 The specified limit may be no higher than the unsigned type’s MAX e.g. 255 for u8

Implementations on Foreign Types§

source§

impl CycleAdd<u8> for u8

source§

fn cycle_add(&self, other: &u8, base: u8) -> u8

source§

fn cycle_sub(&self, other: &u8, base: u8) -> u8

source§

fn series_add(&self, other: &u8, limit: u8) -> u8

source§

fn series_sub(&self, other: &u8, limit: u8) -> u8

source§

fn series_mod(&self, limit: u8) -> u8

source§

impl CycleAdd<u16> for u16

source§

fn cycle_add(&self, other: &u16, base: u16) -> u16

source§

fn cycle_sub(&self, other: &u16, base: u16) -> u16

source§

fn series_add(&self, other: &u16, limit: u16) -> u16

source§

fn series_sub(&self, other: &u16, limit: u16) -> u16

source§

fn series_mod(&self, limit: u16) -> u16

source§

impl CycleAdd<u32> for u32

source§

fn cycle_add(&self, other: &u32, base: u32) -> u32

source§

fn cycle_sub(&self, other: &u32, base: u32) -> u32

source§

fn series_add(&self, other: &u32, limit: u32) -> u32

source§

fn series_sub(&self, other: &u32, limit: u32) -> u32

source§

fn series_mod(&self, limit: u32) -> u32

Implementors§