rust - How do I disable an entire example based on features? -
my rust project has examples relevant features.
i can ignore main function with:
#[cfg(feature = "foo")] fn main() { but other statements depend on feature cause errors when run cargo test. have use number of cfg attribute statements on functions , use statements disable code depends on feature.
is there way ignore entire example file based on feature configuration?
also, because main hidden without feature, cargo test has error:
error: main function not found
so isn't solution.
make more specific use of #[cfg] directive, providing both main() when foo enabled, , main() when foo not:
extern crate blah; // other code still compile without "foo" feature #[cfg(feature = "foo")] fn main() { use blah::onlyexistswithfoo; // code requires "foo" feature } #[cfg(not(feature = "foo"))] fn main() { // empty main function when "foo" disabled }
Comments
Post a Comment