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:



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>


pub extern crate typenum;



Type operator for primality testing.


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