Crates.io | const-exhaustive |
lib.rs | const-exhaustive |
version | |
source | src |
created_at | 2024-11-28 14:47:12.768229 |
updated_at | 2024-11-28 21:52:01.145614 |
description | Enumerate all values of a type at compile time |
homepage | |
repository | https://github.com/aecsocket/const-exhaustive |
max_upload_size | |
id | 1464584 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
const-exhaustive
Enumerate all values of a type at compile time.
All values of T: Exhaustive
are stored in a GenericArray
- allowing you to access all
values at compile time, and in a const context.
Composable with core
types - supports [T; N]
, tuples up to arity 16, Option<T>
, and
other types in core
.
#[derive(Exhaustive)]
- to implement it on your own types.
#![no_std]
and no alloc
- you can use it anywhere.
use const_exhaustive::Exhaustive;
// there is 1 value of `()`
assert_eq!([()], <()>::ALL.as_slice());
// there are 2 values of `bool`
assert_eq!([false, true], bool::ALL.as_slice());
// works on types with generics
assert_eq!(
[None, Some(false), Some(true)],
Option::<bool>::ALL.as_slice()
);
// write your own exhaustive types
#[derive(Debug, Clone, Copy, PartialEq, Exhaustive)]
enum Direction {
North,
South,
East,
West,
}
assert_eq!(
[
Direction::North,
Direction::South,
Direction::East,
Direction::West,
],
Direction::ALL.as_slice()
);
// works on arbitrarily complex types
#[derive(Debug, Clone, Copy, PartialEq, Exhaustive)]
enum Complex {
Direction(Direction),
More {
foo: Option<bool>,
bar: (Result<Direction, [bool; 4]>),
},
}
Run unit and doc tests:
cargo test
Run miri tests:
cargo +nightly miri test
Test generating docs:
RUSTDOCFLAGS="--cfg docsrs_dep" cargo +nightly doc --workspace --all-features