#互斥 #功能 #相互 # #互斥功能

无 std mutually_exclusive_features

宏,用于检查一组功能中只能同时启用一个或一个都不启用,即所谓的互斥功能

2 个不稳定版本

0.1.0 2024年2月5日
0.0.3 2023年11月9日
0.0.2 2023年11月9日
0.0.1 2023年11月9日

#268Rust 模式

Download history 30057/week @ 2024-03-14 29343/week @ 2024-03-21 25181/week @ 2024-03-28 30350/week @ 2024-04-04 29007/week @ 2024-04-11 34618/week @ 2024-04-18 36156/week @ 2024-04-25 37917/week @ 2024-05-02 37922/week @ 2024-05-09 38486/week @ 2024-05-16 38876/week @ 2024-05-23 42305/week @ 2024-05-30 39764/week @ 2024-06-06 37172/week @ 2024-06-13 39881/week @ 2024-06-20 34092/week @ 2024-06-27

158,942 次每月下载
用于 48 个 crate (4 个直接)

MIT/Apache

8KB

互斥功能

crates.io Build Status docs

Rust 中检查互斥功能的宏


它包含 none_or_one_ofexactly_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!");

无运行时依赖项