I want to write a library, some modules need to support no_std
, and others need to support std
.
I tried to write it with reference to other libraries, but it still seems to be wrong.
Cargo.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 told me:
code is inactive due to #[cfg] directives: feature = "no_std" is disabled
How to control the feature
in lib.rs
correctly?
Moreover, I want to write a model dependent on rayon crate. How can I add it through feature
?