> it is often better to use if cfg!(...) instead of #[cfg(...)] because code behind the latter is eliminated very early
My experience with this is the other way around, especially if you have crates tied to that feature.
The cfg! is a marco that compiles to true/false, so whatever is inside of the if guard needs to compile regardless.
E.g.:
Cargo.toml
[features]
default = []
my_feature = ["deps:feature_dependency"]
[dependencies]
feature_dependency = "1.0.0"
And in code: if cfg!(feature = "my_feature") {
feature_dependency::something::Something::invoke();
}
This will fail if you compile without `my_feature`.