IncDec
X | Twitch | Youtube | Mastodon | GitHub | GitHub Sponsors
Incrementation and decrementation in Rust.
IncDec provides macros and extension traits which make doing incrementation and decrementation of numeric values a bit easier.
Examples
The pp and mm extension methods:
use IncDecExt;
let mut val: u32 = 0;
assert_eq!;
assert_eq!;
The try_pp and try_mm extension methods:
use IncDecExt;
let mut val: u32 = 0;
assert_eq!;
assert_eq!;
assert_eq!;
The opp and omm extension methods:
use IntIncDecExt;
let mut val: u32 = 0;
assert_eq!;
assert_eq!;
assert_eq!;
The wpp and wmm extension methods:
use IntIncDecExt;
let mut val: u32 = 0;
assert_eq!;
assert_eq!;
assert_eq!;
The below tables indicate which trait implementation methods use which core integer methods (where applicable):
| IncDecExt Method | Method Used |
|---|---|
| try_pp | checked_add |
| try_mm | checked_sub |
| IntIncDecExt Method | Method |
|---|---|
| opp | overflowing_add |
| omm | overflowing_sub |
| wpp | wrapping_add |
| wmm | wrapping_sub |
Features
| Feature | Description |
|---|---|
| num | Enable core::num NonZero extension methods. |
Todo
- Add more documentation.
- Add more code examples.
- Add more tests.
- Clean-up the code.
- Support saturating incrementation and decrementation.
Maybe
- Add support for numeric types in other crates.
Coding Style
This project uses a coding style that emphasises the use of white space over keeping the line and column counts as low as possible.
So this:
#
Not this:
#
License
Licensed under either of:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0 (see also: https://www.tldrlegal.com/license/apache-license-2-0-apache-2-0))
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT (see also: https://www.tldrlegal.com/license/mit-license))
at your discretion
Contributing
Please clone the repository and create an issue explaining what feature or features you'd like to add or bug or bugs you'd like to fix and perhaps how you intend to implement these additions or fixes. Try to include details though it doesn't need to be exhaustive and we'll take it from there (dependant on availability).
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.