Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to see all the crates in my project that optionally depend on another crate?

I'm adding parking_lot to my project and I want my dependencies that can optionally use it to use it as well.

For example, I know that Tokio has a feature flag to enable parking_lot, but I want to find all my dependencies that have similar feature flags.

like image 575
Shepmaster Avatar asked Sep 19 '25 20:09

Shepmaster


1 Answers

Yandros on the Rust Discord server whipped up this combination of cargo metadata and jq to list the crates that have an optional dependency on a given package (parking_lot in this example):

cargo metadata --format-version 1 | jq -c '.packages[] | select(
    .dependencies | any(
        (.name == "parking_lot")
        and
        (.optional == true)
    )
) | .name'
like image 158
Shepmaster Avatar answered Sep 23 '25 12:09

Shepmaster