#traits #bounds #expression #boolean #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

#119 in No standard library

Download history 172/week @ 2024-04-03 44/week @ 2024-04-10

216 downloads per month

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