2 个不稳定版本
0.1.0 | 2024年2月5日 |
---|---|
0.0.3 | 2023年11月9日 |
0.0.2 |
|
0.0.1 |
|
#268 在 Rust 模式
158,942 次每月下载
用于 48 个 crate (4 个直接)
8KB
互斥功能
Rust 中检查互斥功能的宏
它包含 none_or_one_of
和 exactly_one_of
宏。
两个宏都检查 Rust 中的互斥功能,但 none_or_one_of
允许不启用任何功能,而 exactly_one_of
则要求恰好启用一个功能。
用法
none_or_one_of
使用您想要互斥的功能的列表调用它
use mutually_exclusive_features::none_or_one_of;
none_or_one_of!("feature1", "feature2", "feature3");
这将生成以下代码
#[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!");
exactly_one_of
与上面相同,但要求恰好启用一个功能
use mutually_exclusive_features::exactly_one_of;
exactly_one_of!("feature1", "feature2", "feature3");
这将生成以下代码
#[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!");