type-nats.rs

Type-level natural numbers in Rust

build status

Synopsis

This library implements type-level natural numbers using traits and associated types. At this stage it is meant to serve as a demonstration more than anything else.

Examples

```rust fn example() { let _: SNat< S>>>> > = Add::< S>> , S> >::query(); let _: SNat< N06 > = Mul::< N03 , N02 >::query(); let _: SNat< N08 > = Exp::< N03 , N02 >::query(); let _: SNat< N24 > = Fac::< N04 >::query();

    assert_eq!(Add::< N03 , N02 >::to_uint(), 5u);
    assert_eq!(Mul::< N03 , N02 >::to_uint(), 6u);
    assert_eq!(Exp::< N03 , N02 >::to_uint(), 8u);
    assert_eq!(Fac::< N04       >::to_uint(), 24u);
}

```

Documentation

See the API documentation here.

Requirements

  1. Rust
  2. Cargo

You can install both with the following:

$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh

See Installing Rust for further details.

Usage

$ cargo build ## build library and binary $ cargo test ## run tests in ./tests $ cargo bench ## run benchmarks in ./benches

Discussion

There is an IRC channel on freenode (chat.freenode.net) at #epsilonz.