This is more spitballing than a "Pre-RFC", but just an idea I had given a particular problem.
Problem: inflexible/unintended feature activation
Let's say we have a Cargo.toml
that looks like this:
[dependencies]
foo = { version = "1", optional = true, default-features = false }
bar = { version = "2", optional = true, default-features = false }
baz = { version = "3", optional = true, default-features = false }
Now we want to add a std
feature, and activate the transitive std
feature of those dependencies. We could do this:
[features]
std = ["foo/std", "bar/std", "baz/std"]
...but that means just by activating std
(perhaps just because we wanted such a feature in the toplevel crate) we pull in all of the dependencies. This is even worse if we do:
[features]
default = ["std"]
std = ["foo/std", "bar/std", "baz/std"]
...because it means we MUST pull in all dependencies by default, even if we might want to include some but exclude others.
Solution: weak features
What'd be nice is if the std
feature could "weakly activate" the corresponding std
features of those optional dependencies: instead of automatically pulling them in, it will activate std
, but only if the parent crate is pulled in via another feature activating it.
Hypothetical syntax using the +
character as a sigil (I don't really care about the concrete syntax or if this is in some way ambiguous, but just to give you an idea of how it could work):
[features]
default = ["std", "foo"]
std = ["foo/std+", "bar/std+", "baz/std+"]
This would:
- Enable the
std
andfoo
features of the toplevel package bydefault
- Enable
foo/std
(i.e. thestd
feature of `foo)
This would not:
- Pull in
bar
andbaz
as dependencies, unless they were activated in some other way (e.g.--features
). But if they were,bar/std
andbaz/std
would be enabled.