inc_dec 0.2.0

Incrementation and decrementation in Rust.
Documentation
  • Coverage
  • 75%
    39 out of 52 items documented9 out of 42 items with examples
  • Size
  • Source code size: 78.26 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 927.62 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • coruscateor/inc_dec
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • coruscateor

IncDec

Crates.io License Downloads Docs Twitch Status

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 inc_dec::IncDecExt;

    let mut val: u32 = 0;

    assert_eq!(1, val.pp());

    assert_eq!(0, val.mm());

The try_pp and try_mm extension methods:


    use inc_dec::IncDecExt;

    let mut val: u32 = 0;

    assert_eq!(Some(1), val.try_pp());

    assert_eq!(Some(0), val.try_mm());

    assert_eq!(None, val.try_mm());

The opp and omm extension methods:


    use inc_dec::IntIncDecExt;

    let mut val: u32 = 0;

    assert_eq!((1, false), val.opp());

    assert_eq!((0, false), val.omm());

    assert_eq!((u32::MAX, true), val.omm());

The wpp and wmm extension methods:


    use inc_dec::IntIncDecExt;

    let mut val: u32 = 0;

    assert_eq!(1, val.wpp());

    assert_eq!(0, val.wmm());

    assert_eq!(u32::MAX, val.wmm());

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:


# fn bar() {} 

fn foo()
{

    bar();

}

Not this:


# fn bar() {} 

fn foo()
{
    bar();
}

License

Licensed under either of:

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.