I notice the new syntax for Cargo features in 1.60,
and test the following features structure to get a summarized table.
Any suggestion is welcomed.
# in root `Cargo.toml`
[dependencies]
a = { path = "./a", optional = true, default-features = false}
b = { path = "./b", optional = true, features = ["bar"]}
[workspace]
members = ["./a", "./b"]
# in the `Cargo.toml` of crate `a`
[features]
foo = []
baz = []
# in the `Cargo.toml` of crate `b`
[features]
bar = []
features in root Cargo.toml
|
a |
b |
a/foo |
a/baz |
b/bar |
|---|---|---|---|---|---|
use-a-with-its-name-disabled = ["dep:a"] |
★ | all-features | unusable | unusable | all-features |
maybe-foo = ["a?/foo"] |
all-features | all-features | all-features | all-features | all-features |
foo-a = ["a/foo"] |
√ | all-features | √ | all-features | all-features |
bar = ["dep:b", "a?/baz"] |
all-features | ★ | all-features | all-features | ★ |
bar-and-maybe-baz = ["b", "a?/baz"] |
all-features | √ | all-features | all-features | √ |
bar-and-baz = ["b", "a/baz"] |
√ | √ | all-features | √ | √ |
Note:
| symbol | whether the column feature is enabled via the row feature |
whether the column feature is usable via --features xx or --all-features flag |
|---|---|---|
all-features |
no | yes |
√ |
yes | yes |
★ |
yes | no |
unusable |
no | no |
That is to say
-
all-featuresmeans the column feature is not enabled via the row feature and is usable via--features xxor--all-featuresflag -
√means the column feature is implicitly enabled via the row feature and also usable -
★means the column feature is implicitly enabled via the row feature but in no way to be explicitly enabled via flags mentioned above -
unusablemeans the column feature is no way to be enabled via the row feature and no way to be explicitly enabled via flags mentioned above
And once there is dep:a, for example, features in root Cargo.toml cannot include features with the name a :
i.e.
# in root `Cargo.toml`
[features]
no-a-any-more = ["dep:a"]
this-line-cause-error = ["a/foo"]