wrapnum

Crates.iowrapnum
lib.rswrapnum
version0.3.2
created_at2024-12-15 23:59:22.896713+00
updated_at2024-12-16 14:28:29.291039+00
descriptionEver wanted to make easy arbitrary number wraparounds? Now you can.
homepage
repositoryhttps://github.com/Elsie19/wrapnum
max_upload_size
id1484518
size11,910
Elsie (Elsie19)

documentation

README

WrapNum

Have you ever found yourself needing a counter with an arbitrary wraparound limit and having to handroll some mediocre implementation? Well here you go. Just set the max value and forget about ever needing to wonder, "did I need to call my wrap function here?"

Installation

To add WrapNum to your project, just run:

cargo add wrapnum

And you're all good to go!

Usage

The main entrypoint for WrapNum is with the wrap! macro. There are multiple ways of using the macro, but the most common use-case is with one value: the max limit:

use wrapnum::wrap;

fn main() {
    let mut my_num = wrap!(5);
    assert_eq!(my_num + 6, 1)
}

It also works with subtraction 😜 (as it should, idk why I wrote that).

You can also pass in two values to specify a min and max, or a range:

use wrapnum::wrap;

fn main() {
    let my_num = wrap!(5..=50); // Same as `wrap!(5, 49)`.
}

Refer to the docs for more information on how to create a WrapNum.

Other than that, there isn't much else. It should behave exactly like an integer type should, and if not, open an issue and we can get it fixed.

Commit count: 0

cargo fmt