typenum is a Rust library for type-level numbers evaluated at compile time. It
currently supports bits, unsigned integers, and signed integers.

Typenum lets you do integer arithmetic without size bounds during compilation. This can be used to encode constraints within the type system that are currently not supported (like for example the size of a piece of memory).

The algorithms are fast enough to work on comparatively large numbers (but don't expect it to run as fast as runtime bounded integer arithmetic) due to clever encoding and careful use of where clauses.

We deem this release fit for public consumption, so if you need some compile time numbers, give typenum a try!

Can you write out this example? Or point to some motivating use cases?

It sounds like a very clever library, but the little examples I see in the documentation are so trivial that there's no reason to write them as expressions in the first place.

For some motivating use cases, you could look at both dimensioned or generic-array. The former encodes SI units in types and uses peano numerals for now (but those are quite slow at compile time, so we'll change it to use typenum soon), while the latter uses it to encode the array size.

Thanks! I played with this a little to make a congruence type, where the modulus is a direct type parameter, then things like Into and most std::ops work nicely. It's quite slow to compile though, compared to explicit modular code, but at least the end result seemed to have similar performance. So that's a win in expressiveness, at least, but I'm not sure if I'll keep using it.

(My toy project for Rust is to do Project Euler problems, which I don't think should be published, even though some people already do. I could share this congruence code though if there's any interest...)