macro_rules! const_for {
    ($C:ident in [ $( $n:literal ),* ] $x:block) => { ... };
    ($C:ident in SIZES $x:block) => { ... };
    ($C:ident in NON_ZERO $x:block) => { ... };
    ($C:ident in BENCH $x:block) => { ... };
    ($C:ident in $S:ident if ( $c:expr ) $x:block) => { ... };
}
Expand description

Compile time for loops with a const variable for testing.

Repeats a block of code with different values assigned to a constant.

const_for!(BITS in [0, 10, 100] {
    const LIMBS: usize = nlimbs(BITS);
    println!("{:?}", Uint::<BITS, LIMBS>::MAX);
});

is equivalent to

println!("{:?}", Uint::<0, 0>::MAX);
println!("{:?}", Uint::<10, 1>::MAX);
println!("{:?}", Uint::<100, 2>::MAX);

It comes with two build-in lists: NON_ZERO which is equivalent to

[1, 2, 63, 64, 65, 127, 128, 129, 256, 384, 512, 4096]

and SIZES which is the same but also has 0 as a value.

In combination with proptest! this allows for testing over a large range of Uint types and values:

const_for!(BITS in SIZES {
   const LIMBS: usize = nlimbs(BITS);
   proptest!(|(value: Uint<BITS, LIMBS>)| {
        // ... test code
    });
});