wrapping_in_range

Crates.iowrapping_in_range
lib.rswrapping_in_range
version0.1.1
created_at2025-09-10 21:21:14.478907+00
updated_at2025-09-10 21:28:44.751029+00
descriptionWrapping arithmetic for any range
homepage
repositoryhttps://github.com/nik-rev/wrapping-in-range
max_upload_size
id1833023
size29,412
Nik Revenco (nik-rev)

documentation

README

github crates.io docs.rs

Wrapping-in-range arithmetic for custom ranges via the WrappingInRange type

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]
);
Commit count: 11

cargo fmt