wrapping_arithmetic

Crates.iowrapping_arithmetic
lib.rswrapping_arithmetic
version0.1.0
sourcesrc
created_at2019-10-17 14:52:03.849715
updated_at2019-10-17 14:52:03.849715
descriptionProc macro #[wrappit] to rewrite operators into their wrapping equivalents.
homepage
repositoryhttps://github.com/franziskuskiefer/wrapping-arithmetic
max_upload_size
id173370
size8,772
Franziskus Kiefer (franziskuskiefer)

documentation

README

This crate provides a proc macro that rewrites arithemtic operators +,-,* into their wrapping equivalents wrapping_add, wrapping_sub, wrapping_mul as well as their assigning versions +=,-=,*=.

The following function for example

#[wrappit]
fn mix(a: u32, b: u32, c: [u32; 8]) -> u32 {
    let mut r = a + b;
    for u in c {
        r *= u;
    }
    r
}

is rewritten to

fn mix(a: u32, b: u32, c: [u32; 8]) -> u32 {
    let mut r = a.wrapping_add(b);
    for u in c {
        r = r.wrapping_mul(u);
    }
    r
}
Commit count: 11

cargo fmt