【问题标题】:How to find the current version of a Rust library?如何找到 Rust 库的当前版本?
【发布时间】:2021-10-30 11:31:43
【问题描述】:

Cargo.toml 文件要求我说明依赖项的版本,例如rand = "0.6".

我想使用包rand_pcg,但不知道版本。我怎样才能找到它?

【问题讨论】:

    标签: rust dependencies version rust-cargo


    【解决方案1】:

    使用网络

    crates.io

    导航到https://crates.io/,在搜索框中输入您的 crate 名称,然后查看版本。您也可以单击剪贴板图标复制完整的依赖项以添加到 Cargo.toml。

    docs.rs

    导航到https://docs.rs/,在搜索框中输入您的 crate 名称,然后查看版本。如果点击进入 crate,然后可以点击剪贴板图标复制完整的依赖项以添加到 Cargo.toml。

    lib.rs

    导航到https://lib.rs/,在搜索框中输入您的 crate 名称,然后查看版本。如果您点击进入 crate,然后您可以点击“安装”选项卡查看添加到 Cargo.toml 的完整依赖项。

    使用命令行

    cargo build

    将通配符依赖项添加到您的 Cargo.toml(例如 rand_pcg = "*")。运行cargo build 并记下它选择的版本(例如Compiling rand_pcg v...)或在Cargo.lock 中查找板条箱的条目。编辑 Cargo.toml 以使用此版本。

    cargo add

    安装cargo edit,然后运行cargo add rand_pcg。这是我的首选路线。

    请参阅Is there a command to automatically add a crate to my Cargo.toml? 了解更多信息。

    cargo search

    作为mentioned by user2722968,你可以运行cargo search rand-pcg,它会输出依赖行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-05
      • 2017-05-09
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      • 2017-03-07
      • 1970-01-01
      相关资源
      最近更新 更多