feature_utils

Crates.iofeature_utils
lib.rsfeature_utils
version0.0.0
sourcesrc
created_at2022-11-22 06:23:16.362897
updated_at2022-11-22 06:23:16.362897
descriptionMacros for good compiler errors when dealing with feature flags
homepage
repositoryhttps://github.com/TheButlah/feature_utils
max_upload_size
id720634
size16,375
Ryan Butler (TheButlah)

documentation

README

Feature Utils

This crate implements a collection of helpful feature-related macros. These macros serve to make it easy to have helpful compiler messages when dealing with sets of related, sometimes mutually exclusive features.

Stability

We are pre-0.1, so we make no stability guarantees currently. Cargo consideres 0.0.* to mean that all new versions are possibly breaking changes.

Example

Inside build.rs:

// Each of these embedded microcontrollers are mutually exclusive and at least one
// must be provided.
feature_utils::mandatory_and_unique!("esp32c3", "esp8266", "nrf52840");
fn main() {}

This results in one message if you don't pass any features:

error: You must provide one of the mandatory features!
 --> src/lib.rs:18:1
  |
5 | feature_utils::mandatory_and_unique!("esp32c3", "esp8266", "nrf52840");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `$crate::at_least_one_provided` which comes
from the expansion of the macro `feature_utils::mandatory_and_unique` (in Nightly
builds, run with -Z macro-backtrace for more info)

And another message if you pass multiple mutually exclusive features:

error: features "esp32c3" and "nrf52840" cannot be used together!
 --> src/lib.rs:18:1
  |
5 | feature_utils::mandatory_and_unique!("esp32c3", "esp8266", "nrf52840");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `$crate::unique` which comes from the
expansion of the macro `feature_utils::mandatory_and_unique` (in Nightly builds, run
with -Z macro-backtrace for more info)

License

All code in this repository is dual-licensed under either:

at your option. This means you can select the license you prefer!

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.

Commit count: 1

cargo fmt