Rust Crate for Specifying Bounds With Boolean Expressions
=========================================================
This crate works with `no_std`.
This crate can be compiled with the latest stable Rust toolchain. However, it is
useless without the unstable feature [`generic_const_exprs`].
[`generic_const_exprs`]: <https://github.com/rust-lang/rust/issues/76560>
A simple example is listed below:
```rust
#![feature(generic_const_exprs)]
use bool_const::*;
struct MyEvenLengthArray<T, const N: usize>
where
BoolConst<{ N % 2 == 0 }>: TrueConst,
{
inner: [T; N],
}
```
`bool_const` provides simpler interfaces compared to the code that the Rust
compiler will suggest:
```rust
struct MyEvenLengthArray<T, const N: usize>
where
[(); { N % 2 == 0 } as usize]:,
{
inner: [T; N];
}
```
The Rust compiler rejects overly complex generic const expression, so you should
write a `const fn` to satisfy it:
```rust
#![feature(generic_const_exprs)]
use bool_const::*;
#[allow(dead_code)]
struct TheLeapYearType<const N: i64>
where
BoolConst<{ is_leap_year(N) }>: TrueConst;
const fn is_leap_year(year: i64) -> bool {
...
}
```
More examples can be found in [examples] directory.
License
-------
MIT