assert_cfg 0.1.0

static assertions for crate features, with descriptive errors.
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented5 out of 5 items with examples
  • Size
  • Source code size: 21.28 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 979.01 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • rodrimati1992/assert_cfg
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • rodrimati1992

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.