Crate typenum_prime[][src]

Compile-time primality testing of typenum integers.

The current algorithm is trial division by every prime number from 2 up to next_integer_power_of_two(sqrt(n)). The default compiler recursion limit could sometimes be insufficient, depending on the magnitude of the integer being tested. When necessary, raise it using a crate attribute:

#![recursion_limit="128"]

Example

The intended use of this crate is to put a bound on type-level integer parameters so the compiler enforces their primality. For instance, you might want the number of buckets in a statically-sized hash table to always be a prime number so that hash collisions are reduced. Now you can let the compiler enforce this constraint.

This example is not tested
pub struct StaticHashTable<K,V,N>
    where N: Prime + ArrayLength<Option<(K,V)>> {
    buckets: GenericArray<Option<(K,V)>,N>
}

Re-exports

pub extern crate typenum;

Traits

IsPrime

Type operator for primality testing.

Prime

Marker trait for prime, unsigned integers; equivalent to IsPrime<Output=True>