#traits #bounds #boolean #expression #generics #no-alloc

no-std bool_traits

Use boolean expressions as trait bounds

2 releases

0.1.1 Apr 7, 2024
0.1.0 Apr 7, 2024

#214 in No standard library

MIT license

3KB

bool_traits

bool_traits

Use boolean expressions as trait bounds.

Examples

#![feature(generic_const_exprs)]

use bool_traits::*;

fn create_small_u8_array<const N: usize>() -> [u8; N]
    where
        (): True<{ N <= 4 }>,
{
    [0; N]
}
// this compiles:
let array = create_small_u8_array::<3 > ();
// this does not:
let array = create_small_u8_array::<5 > ();

lib.rs:

Use boolean expressions as trait bounds.

Examples

#![feature(generic_const_exprs)]

use bool_traits::*;

fn create_small_u8_array<const N: usize>() -> [u8; N]
where
    (): True<{ N <= 4 }>,
{
    [0; N]
}

// this compiles:
let array = create_small_u8_array::<3>();
// this does not:
let array = create_small_u8_array::<5>();

No runtime deps