4 releases
| 0.1.3 | Oct 13, 2025 |
|---|---|
| 0.1.2 | Oct 13, 2025 |
| 0.1.1 | Sep 10, 2025 |
| 0.1.0 | Sep 10, 2025 |
#775 in Math
18KB
400 lines
wrapping_in_range
Wrapping-in-range arithmetic for custom ranges via the WrappingInRange type
[dependencies]
wrapping_in_range = "0.1"
These arithmetic operations act just like std's .wrapping_sub(), .wrapping_add(), etc. but for a custom user-provided range.
Examples
use wrapping_in_range::WrappingInRange;
let w = |i: i16| WrappingInRange(i, -1..=1);
assert_eq!(
[-2, -1, 0, 1, 2].map(|i| w(i) - 1),
[ 0, 1, -1, 0, 1]
);
assert_eq!(
[-2, -1, 0, 1, 2].map(|i| w(i) + 1),
[-1, 0, 1, -1, 0]
);
Dependencies
~140KB