#assertions #assert #cfg #no-std

no-std assert_cfg

static assertions for crate features, with descriptive errors

1 unstable release

0.1.0 Aug 24, 2022

#40 in #cfg

Download history 3/week @ 2024-07-19 4/week @ 2024-07-26 190/week @ 2024-08-23 83/week @ 2024-08-30 59/week @ 2024-09-06 92/week @ 2024-09-13 108/week @ 2024-09-20 118/week @ 2024-09-27 57/week @ 2024-10-04 95/week @ 2024-10-11 52/week @ 2024-10-18 81/week @ 2024-10-25 117/week @ 2024-11-01

355 downloads per month

Zlib license

16KB
212 lines

Rust crates-io api-docs

Static assertions for crate features, with informative errors.

The macros from this crate print which specific features are responsible for the assertion failure.

Examples

Exactly one feature

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"`

No-std support

assert_cfg is #![no_std], it can be used anywhere Rust can be used.

Minimum Supported Rust Version

This requires Rust 1.57.0, because it uses the panic macro in a const context.

Dependencies

~215KB