Crates.io | mutually_exclusive_features |
lib.rs | mutually_exclusive_features |
version | 0.1.0 |
source | src |
created_at | 2023-11-09 10:04:47.835501 |
updated_at | 2024-02-05 14:09:22.3576 |
description | Macros to check that only none or one of a set of features is enabled at a time, as known as mutually exclusive features |
homepage | |
repository | https://github.com/omid/mutually_exclusive_features |
max_upload_size | |
id | 1029981 |
size | 10,260 |
features
in RustIt contains none_or_one_of
and exactly_one_of
macros.
Both check mutually exclusive features in Rust,
but none_or_one_of
allows for no features to be enabled,
while exactly_one_of
requires exactly one feature to be enabled.
Call it with the list of features you want to be mutually exclusive:
use mutually_exclusive_features::none_or_one_of;
none_or_one_of!("feature1", "feature2", "feature3");
Which will generate the following code:
#[cfg(all(feature="feature1", feature="feature2"))]
compile_error!("The `feature1` and `feature2` features are mutually exclusive and cannot be enabled at the same time!");
#[cfg(all(feature="feature1", feature="feature3"))]
compile_error!("The `feature1` and `feature3` features are mutually exclusive and cannot be enabled at the same time!");
#[cfg(all(feature="feature2", feature="feature3"))]
compile_error!("The `feature2` and `feature3` features are mutually exclusive and cannot be enabled at the same time!");
It's the same, but requires exactly one feature to be enabled:
use mutually_exclusive_features::exactly_one_of;
exactly_one_of!("feature1", "feature2", "feature3");
Which will generate the following code:
#[cfg(all(feature="feature1", feature="feature2"))]
compile_error!("The `feature1` and `feature2` features are mutually exclusive and cannot be enabled at the same time!");
#[cfg(all(feature="feature1", feature="feature3"))]
compile_error!("The `feature1` and `feature3` features are mutually exclusive and cannot be enabled at the same time!");
#[cfg(all(feature="feature2", feature="feature3"))]
compile_error!("The `feature2` and `feature3` features are mutually exclusive and cannot be enabled at the same time!");
#[cfg(not(any(feature="feature1", feature="feature2", feature="feature3")))]
compile_error!("You must enable exactly one of `feature1`, `feature2`, `feature3` features!");