const_power_of_two/lib.rs
1//! # `const_power_of_two`
2//!
3//! This crate provides a set of traits that allow you to work with power-of-two
4//! values in a constant generic context.
5//!
6//! # Examples
7//!
8//! You can use the traits as bounds in constant generic contexts.
9//!
10//! ```
11//! use const_power_of_two::PowerOfTwoUsize;
12//!
13//! trait MyTrait<const N: usize>
14//! where
15//! usize: PowerOfTwoUsize<N>,
16//! {
17//! // Your code here...
18//! }
19//! ```
20//!
21//! As you can see in the example above, the integer type is what implements the
22//! trait. This was done to make this library rather light and easy to use.
23//!
24//! If you use something that is not a power of two, you will get a compile-time
25//! error.
26
27#![cfg_attr(docsrs, feature(doc_cfg))]
28#![no_std]
29
30/// A prelude that re-exports all the traits in this crate.
31pub mod prelude {
32 #[doc(inline)]
33 pub use super::{
34 PowerOfTwoU128,
35 PowerOfTwoU16,
36 PowerOfTwoU32,
37 PowerOfTwoU64,
38 PowerOfTwoU8,
39 PowerOfTwoUsize,
40 };
41}
42
43// NOTE: Practically all of the code in this crate is generated by `build.rs`.
44include!(concat!(env!("OUT_DIR"), "/generated.rs"));