【问题标题】:Is there a way to see all the crates in my project that optionally depend on another crate?有没有办法查看我的项目中可选依赖另一个 crate 的所有 crate?
【发布时间】:2021-05-23 15:46:26
【问题描述】:

我正在将parking_lot 添加到我的项目中,并且我希望我的依赖项也可以选择使用它。

例如,我知道 Tokio 有一个功能标志来启用 parking_lot,但我想找到我所有具有相似功能标志的依赖项。

【问题讨论】:

    标签: rust rust-cargo


    【解决方案1】:

    Rust Discord 服务器上的 Yandros 生成了 cargo metadatajq 的组合,以列出对给定包具有可选依赖关系的 crate(本例中为 parking_lot):

    cargo metadata --format-version 1 | jq -c '.packages[] | select(
        .dependencies | any(
            (.name == "parking_lot")
            and
            (.optional == true)
        )
    ) | .name'
    

    【讨论】:

      猜你喜欢
      • 2011-03-18
      • 2021-01-25
      • 2020-10-01
      • 2021-12-23
      • 1970-01-01
      • 1970-01-01
      • 2017-03-09
      • 2020-09-02
      • 1970-01-01
      相关资源
      最近更新 更多