wrapping_macros
A macro for scoped wrapping arithmetic.
Any code within a wrapping! { .. } block will be transformed as follows:
a + bbecomesa.wrapping_add(b). Similarly for-,*,/,%,<<,>>.a += bbecomesa = a.wrapping_add(b). Similarly for-=,*=,/=,%=,<<=,>>=.-abecomesa.wrapping_neg().
Cargo
Add this to your Cargo.toml:
= "*"
Examples
let a = 128u8;
let b = wrapping! ;
assert_eq!;
let mut a = 250u8;
let mut b = 4u8;
let mut c = 100u8;
wrapping!
assert_eq!;
assert_eq!;
assert_eq!;
use wrapping;
assert_eq!;
Caveat
You cannot nest another macro invocation within a wrapping! block. For example, this will not work:
let x = 128u8;
wrapping!
Instead, move the macro call out of the wrapping! block:
let x = 128u8;
println!
Inspired by wrapping_macros crate by lfairy