# `const_power_of_two`
[](https://github.com/seancroach/const_power_of_two)
[](https://crates.io/crates/const_power_of_two)
[](https://docs.rs/const_power_of_two)
[](https://github.com/seancroach/const_power_of_two/actions?query=branch%3Amain)
A crate for working with constant generics that are powers of two.
## Usage
Add the following to your `Cargo.toml`:
```toml
[dependencies]
const_power_of_two = "1"
```
Then, import the corresponding trait for your argument type, and add it to your
trait or implementation's `where` bounds:
```rust
use const_power_of_two::PowerOfTwoUsize;
trait MyTrait
where
usize: PowerOfTwoUsize,
{
// ...
}
struct Test;
// NOTE: This is valid, and no error is emitted.
impl MyTrait<4> for Test {}
// NOTE: This will emit an error at compile-time.
impl MyTrait<10> for Test {}
```
The integer type is what implements the trait, as you can see above. It's not
the most common Rust pattern, but it's easy to work with once you've seen it
in action. At compile-time, if `ALIGNMENT` isn't a power of two, an error will
get emitted.
## Documentation
You can view the documentation on docs.rs [here](https://docs.rs/const_power_of_two).
## License
Licensed under either of
- Apache License, Version 2.0
([LICENSE-APACHE](https://github.com/seancroach/const_power_of_two/blob/main/LICENSE-APACHE)
or )
- MIT license
([LICENSE-MIT](https://github.com/seancroach/const_power_of_two/blob/main/LICENSE-MIT)
or )
at your option.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.