checks
Adds several compile time checks for const generics.
Idea was based off of this reddit post.
Note: This library requires use of the #![feature(generic_const_exprs)] flag.
Usage:
/// Only allows for arguments of `C` to be alphabetic
;
// All letters are alphabetic, check passes.
let pass = ; // Compiles
let pass = ; // Compiles
let pass = ; // Compiles
// Letters are not alphabetic, check fails.
let fail = ; // Compile error!
let fail = ; // Compile error!
let fail = ; // Compile error!
Custom checks can be implemented as well:
const
>: Passed;
let pass = ; // Compiles
let pass = ; // Compiles
let fail = ; // Compiler error!
Checks can also be defined with the check! macro, which will
also generate documentation / tests for example input:
check!
;
let pass = ; // Compiles
let pass = ; // Compiles
let fail = ; // Compiler error!
Full list of provided checks can be found on the docs.rs page.