Crate inc_dec

Source
Expand description

§Inc Dec

Crates.io License Downloads Docs Twitch Status

X | Twitch | Youtube | Mastodon | GitHub | GitHub Sponsors

Incrementation and decrementation in Rust.

§Examples - Extension Traits:

The pp and mm methods:


    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:


    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:


    use inc_dec::pp;

    let mut int_val = 1;

    pp!(int_val);

    assert_eq!(2, int_val);

The ppf macro:


    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:


    use inc_dec::mm;

    let mut int_val = 2;

    mm!(int_val);

    assert_eq!(1, int_val);

The mmf macro:


    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:

MethodIncDecSelf Method
checked_addtry_pp
checked_subtry_mm
MethodIntIncDecSelf Method
overflowing_addopp
overflowing_subomm
wrapping_addwpp
wrapping_subwmm

§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:



fn foo()
{

    bar();

}

Not this:



fn foo()
{
    bar();
}

§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.

Macros§

checked_mm_mut
Calls checked_sub on an integer with 1 as a parameter.
checked_pp_mut
Calls checked_add on an integer with 1 as a parameter.
mm
Decrements the provided integer by one.
mm_mut
Decrements the provided integer by one and returns it.
mmf
Decrements the provided floating point number by one.
mmf_mut
Decrements the provided floating point number by one and returns it.
omm_mut
Calls overflowing_sub on an integer with 1 as a parameter.
opp_mut
Calls overflowing_add on an integer with 1 as a parameter.
pp
Increments the provided integer by one.
pp_mut
Increments the provided integer by one and returns it.
ppf
Increments the provided floating point number by one.
ppf_mut
Increments the provided floating point number by one and returns it.
wmm_mut
Calls wrapping_sub on an integer with 1 as a parameter.
wpp_mut
Calls wrapping_add on an integer with 1 as a parameter.

Traits§

IncDecSelf
For implementing incrementation and decrementation on Self.
IntIncDecSelf
For implementing integer-only incrementation and decrementation on Self.