step 0.2.0

A trait that allows for stepping numeric types.
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented1 out of 7 items with examples
  • Size
  • Source code size: 4.82 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.38 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ryanq
step-0.2.0 has been yanked.

step

Build Status Crate on crates.io

step is a crate that provides the trait Step, which allows for unit steps and arbitrary steps on numeric types.

Documentation can be found on docs.rs.

Using step

Add the crate to the dependencies section of Cargo.toml:

[dependencies]
step = { git = "https://github.com/ryanq/step" }

Then import the crate and type in your source:

extern crate step;

use step::Step;

Then you can use the functions for incrementing and decrementing numbers or implement it on your own types:

let number = 42;

assert_eq!(number.next(), 43);
assert_eq!(number.next_by(&3), 45);
assert_eq!(number.prev(), 41);
assert_eq!(number.prev_by(&3), 39);
struct Foo {
    bar: i32,
}

impl Step for Foo {
    fn next(&self) -> Self { Foo { bar: self.bar + 1 } }
    fn next_by(&self, by: &Self) -> Self { Foo { bar: self.bar + *by } }
    fn prev(&self) -> Self { Foo { bar: self.bar - 1 } }
    fn prev_by(&self, by: &Self) -> Self { Foo { bar: self.bar - *by } }
}