How to work on optional feature library?

Hi Guys!

I have a library which have have optional features. Its important because there are feature related dependencies, that can expand the build size and time as well.

But when I use these optional features, rust-analyzer doesnt handle my optional feature related code. No hint, no error checking. If I use them it as a default feature, then its ok, but then I need to use default_features = false in the the project where it is a dependency.

So is there any way to not use default features, just optional ones, and somehow force rust-analyzer to handle the optional code as well - during the development?

Here is my cargo.toml part

[features]
default = ["proto", "id"]
id = []
proto = ["futures", "prost", "tokio", "tonic"]

[dependencies]
futures = {version = "0.3.5", optional = true}
prost = {version = "0.6", optional = true}
tokio = {version = "0.2", features = ["macros"], optional = true}
tonic = {version = "0.3.1", optional = true}

and here is my lib.rs

#[cfg(feature = "id")]
pub mod id;
pub mod prelude;
#[cfg(feature = "proto")]
pub mod proto;

and here is the project: https://github.com/gardenzilla/gzlib

Thank you in advance!

I believe you'll need to configure the features that RA activates via rust-analyzer.cargo.features (a collection (list/array/...) of feature names) and/or rust-analyzer.cargo.allFeatures (bool).

See the user manual's configuration section for more details.

4 Likes

Thank you! It works! :heart:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.