bool_const 1.0.0

A crate for generic const boolean expressions.
Documentation
// Copyright (c) 2025 GreenYun Organization
// SPDX-License-Identifier: MIT

//! The boolean constant library.
//!
//! The library benefits the use of generic const boolean expressions as type
//! bounds.
//!
//! This library can be compiled with the latest stable Rust compiler, but it is
//! useless unless the `generic_const_exprs` feature is enabled, which requires
//! nightly Rust toolchains.
//!
//! ## Example
//!
//! ```
//! #![feature(generic_const_exprs)]
//!
//! use bool_const::*;
//!
//! struct MyEvenLengthArray<T, const N: usize>
//! where
//!     BoolConst<{ N.is_multiple_of(2) }>: TrueConst,
//! {
//!     inner: [T; N],
//! }
//! ```
//!
//! ## Handling Compilation Errors
//!
//! If there is a type bound error on [`TrueConst`], the Rust compiler may throw
//! the "unconstrained generic constant" error, and the message may look like
//! this:
//!
//! ```text
//! required by a bound in `MyEvenLengthArray`
//! try adding a `where` bound: ` where [(); { N.is_multiple_of(2) } as usize]:`
//! ```
//!
//! However, you should not simply apply that suggested code, because it is not
//! allowed by the type checker (since `MyEvenLengthArray` is constrained by
//! `BoolConst<{ ... }>: TrueConst`). Instead, you should write:
//!
//! ```ignore
//! # struct AnotherType<T, const N: usize>
//! where BoolConst<{ N.is_multiple_of(2) }>: TrueConst
//! # {
//! #     inner: [T; N],
//! # }
//! ```

#![no_std]

/// The `TrueConst` trait.
///
/// *[See crate-level documentation.](crate).*
pub trait TrueConst {}

/// The `BoolConst` type.
///
/// *[See crate-level documentation.](crate).*
pub struct BoolConst<const B: bool>;

impl TrueConst for BoolConst<true> {}