How to set dependency feature based on the the status of a feature of current crate?

In detail, suppose I am writing a lib create A, which depends on crate B.
B has some feature feature_b, which can be turned on or off
A also has some feature feature_a, which can be turn on/off.
If I want to link feature_b to feature_a, how can I express it in the Cargo.toml of create A?

i.e., How can I express that if feature_a is turned on, B’s feature_b should also be turned_on, otherwise, turn it off

The concrete problem I am trying to solve is try to adapt rust-numpy to python 2.7 (which originally only support python3).

rust-numpy relies on rust-cpython, which has two features python3-sys and python27-sys, to determine which python to support.

I want to two features to rust-numpy (just use python3-sys and python27-sys).

How can I modify the Cargo.toml so that I can configure the feature of numpy-cpython according to the feature of rust-numpy that is turned on?

1 Like

In the features section you can make your feature depend on <crate>/<feature>:

optional = true

feature_a = ["b/feature_b"]

Thanks, that’s exactly what I need.