#const-generics #predicates #future #taste

generic-predicates

A taste of what const generics could enable in the future

1 unstable release

0.1.0 Jun 24, 2022

#7 in #predicates

22 downloads per month

MIT license

5KB
53 lines

A taste of what const generics could enable in the future

#![feature(generic_const_exprs)]

use generic_predicates::generic_predicates;

generic_predicates! {
    pub fn foo<const N: usize>()
    where
        (N > 23, "`N` must be greater than 23")
    {

    }
}

fn main() {
    // This compiles.
    foo::<24>();

    // This doesn't.
    foo::<23>();
}

lib.rs:

A taste of what const generics could enable in the future.

#![feature(generic_const_exprs)]

use generic_predicates::generic_predicates;

generic_predicates! {
    pub fn foo<const N: usize>()
    where
        (N > 23, "`N` must be greater than 23")
    {

    }
}

fn main() {
    // This compiles.
    foo::<24>();

    // This doesn't.
    foo::<23>();
}

Dependencies

~1.5MB
~34K SLoC