Declaring optional supportive leaf features
⚓ Rust 📅 2026-05-30 👤 surdeus 👁️ 2Hi,
when defining features for a Cargo package I questioned how I can define valid feature combinations.
For example lets imagine you have one or more supportive (backend) features, which can be used/consumed within other features. They could provide a service.
Then it's relatively simple to declare a dependency like this:
[features]
service_feature_c = []
consuming_feature_a = ["service_feature_c"]
consuming_feature_b = ["service_feature_c"]
i.e. you can express that
(a OR b) => c (in the case of an optional feature, you probably do not declare it as a dependency)
but you can't declare additional conditions about the inverse direction. i.e. it should not be allowed to enable c without a or b (i.e. c alone does not provide any value without a or b).
c => (a OR b)
Is there a common approach to handle this by somehow disallowing invalid or unsupported feature combinations?
BR
5 posts - 3 participants
🏷️ Rust_feed