Crates.io | type-nats |
lib.rs | type-nats |
version | 0.0.2 |
source | src |
created_at | 2014-12-29 08:12:50.313613 |
updated_at | 2015-12-11 23:59:34.806356 |
description | Type-level natural numbers in Rust |
homepage | |
repository | https://github.com/darinmorrison/type-nats.rs |
max_upload_size | |
id | 659 |
size | 11,726 |
Type-level natural numbers in Rust
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.
fn example() {
let _: SNat< S<S<S<S<S<Z>>>>> > = Add::< S<S<S<Z>>> , S<S<Z>> >::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);
}
See the API documentation here.
You can install both with the following:
$ curl -s https://static.rust-lang.org/rustup.sh | sudo sh
See Installing Rust for further details.
$ cargo build ## build library and binary
$ cargo test ## run tests in ./tests
$ cargo bench ## run benchmarks in ./benches
There is an IRC channel on freenode (chat.freenode.net) at #epsilonz.