| Crates.io | assert_cfg |
| lib.rs | assert_cfg |
| version | 0.1.0 |
| created_at | 2022-08-24 08:51:20.848802+00 |
| updated_at | 2022-08-24 08:51:20.848802+00 |
| description | static assertions for crate features, with descriptive errors. |
| homepage | |
| repository | https://github.com/rodrimati1992/assert_cfg/ |
| max_upload_size | |
| id | 651554 |
| size | 15,146 |
Static assertions for crate features, with informative errors.
The macros from this crate print which specific features are responsible for the assertion failure.
This example demonstrates the exactly_one macro,
which asserts that exactly one of the listed features is enabled.
assert_cfg::exactly_one!{
feature = "foo",
feature = "bar",
feature = "qux",
}
When the "foo" and "bar" features are enabled,
the above code produces this compile-time error:
error[E0080]: evaluation of constant value failed
--> src/lib.rs:15:1
|
4 | / assert_cfg::exactly_one!{
5 | | feature = "foo",
6 | | feature = "bar",
7 | | feature = "qux",
8 | | }
| |_^ the evaluated program panicked at '
too many features were enabled, only one of them can be enabled:
- `feature = "foo"`
- `feature = "bar"`
assert_cfg is #![no_std], it can be used anywhere Rust can be used.
This requires Rust 1.57.0, because it uses the panic macro in a const context.