https://github.com/coruscateor/inc_dec
Incrementation and decrementation in Rust.
https://github.com/coruscateor/inc_dec
decrement extension floating-point increment integer rust rust-lang rustlang
Last synced: 4 months ago
JSON representation
Incrementation and decrementation in Rust.
- Host: GitHub
- URL: https://github.com/coruscateor/inc_dec
- Owner: coruscateor
- License: apache-2.0
- Created: 2025-03-21T02:18:59.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-01T00:34:17.000Z (about 1 year ago)
- Last Synced: 2025-11-27T09:43:40.682Z (7 months ago)
- Topics: decrement, extension, floating-point, increment, integer, rust, rust-lang, rustlang
- Language: Rust
- Homepage: https://coruscateor.com/projects/inc-dec
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE-MIT
Awesome Lists containing this project
README
# Inc Dec
[](https://crates.io/crates/inc_dec)
[](#license)
[](https://crates.io/crates/inc_dec)
[](https://docs.rs/inc_dec/latest/inc_dec/)
[](https://www.twitch.tv/coruscateor)
[X](https://twitter.com/Coruscateor) |
[Twitch](https://www.twitch.tv/coruscateor) |
[Youtube](https://www.youtube.com/@coruscateor) |
[Mastodon](https://mastodon.social/@Coruscateor) |
[GitHub](https://github.com/coruscateor) |
[GitHub Sponsors](https://github.com/sponsors/coruscateor)
Incrementation and decrementation in Rust.
## Examples - Extension Traits:
The pp and mm methods:
```rust
use inc_dec::IncDecSelf;
let mut u32_val: u32 = 0;
assert_eq!(1, u32_val.pp());
assert_eq!(0, u32_val.mm());
```
The try_pp and try_mm methods:
```rust
use inc_dec::IncDecSelf;
let mut u32_val: u32 = 0;
assert_eq!(Some(1), u32_val.try_pp());
assert_eq!(Some(0), u32_val.try_mm());
assert_eq!(None, u32_val.try_mm());
```
## Examples - Macros:
The pp macro:
```rust
use inc_dec::pp;
let mut int_val = 1;
pp!(int_val);
assert_eq!(2, int_val);
```
The ppf macro:
```rust
use inc_dec::ppf;
let mut f32_val: f32 = 1.0;
ppf!(f32_val);
assert_eq!(2.0, f32_val);
let mut f64_val = 1.0;
ppf!(f64_val);
assert_eq!(2.0, f64_val);
```
The mm macro:
```rust
use inc_dec::mm;
let mut int_val = 2;
mm!(int_val);
assert_eq!(1, int_val);
```
The mmf macro:
```rust
use inc_dec::mmf;
let mut f32_val: f32 = 2.0;
mmf!(f32_val);
assert_eq!(1.0, f32_val);
let mut f64_val = 2.0;
mmf!(f64_val);
assert_eq!(1.0, f64_val);
```
Aside from regular incrementation and decrementation, the following core library integer methods are used (With associated trait method names) in the integer implementations of the IncDecSelf and IntIncDecSelf traits:
| Method | IncDecSelf Method |
| ------ | ----------- |
| checked_add | try_pp |
| checked_sub | try_mm |
| Method | IntIncDecSelf Method |
| ------ | ----------- |
| overflowing_add | opp |
| overflowing_sub | omm |
| wrapping_add | wpp |
| wrapping_sub | wmm |
## No-Std
You don't need it.
## Todo:
- Add more documentation
- Add more code examples
- Add more tests
- Clean-up the code
- Add support for non-zero integers (core::num).
## 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:
```rust
# fn bar() {}
fn foo()
{
bar();
}
```
Not this:
```rust
# fn bar() {}
fn foo()
{
bar();
}
```
## License
Licensed under either of:
- Apache License, Version 2.0, ([LICENSE-APACHE](./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](./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.