External Publication
Visit Post

Optional features are part of the crate — the project should say so

Rust Internals [Unofficial] March 11, 2026
Source

pacak:

You can add something like in your Cargo.toml

[dev-dependencies]
mycrate = { path = ".", features = ["stuff", "disabled", "by", "default"] }

epage:

Not finding the issue right now but this can get confusing results in some cases.

This also makes it more difficult to test without features which can be important in some cases.

A more flexible way to get this same effect today is to add another package in the same workspace which has this dependency. Then, builds using the default set of workspace members will have the features, and cargo test -p mycrate will not.

But it might not be desirable to apply the features to all default-members builds, only editing. So, it might make sense for Cargo to offer a feature list, not as a config, but as a workspace property or properties — some sort of workspace.default-features-for-development. This would have the advantage over config that the features apply exactly to the workspace (which is the scope at which feature names mean something) rather than the current directory.

Discussion in the ATmosphere

Loading comments...