wrapping_arithmetic 0.1.0

Proc macro #[wrappit] to rewrite operators into their wrapping equivalents.
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 9.35 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 283.3 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • franziskuskiefer/wrapping-arithmetic
    3 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • franziskuskiefer

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
}