我想写一个库,有的模块需要支持no_std
,有的模块需要支持std
。
我尝试参考其他库来编写它,但它似乎仍然是错误的。
货物.toml:
[features]
default = ["std"]
std = []
lib.rs:
#![cfg_attr(feature = "no_std", no_std)]
#[cfg(feature = "no_std")]
pub mod no_std;
#[cfg(feature = "std")]
pub mod std;
Rust Analyzer 告诉我:
code is inactive due to #[cfg] directives: feature = "no_std" is disabled
如何正确控制feature
in lib.rs
?
此外,我想写一个依赖于rayon
crate 的模型。我怎样才能通过添加它feature
?