【发布时间】:2021-10-30 11:31:43
【问题描述】:
Cargo.toml 文件要求我说明依赖项的版本,例如rand = "0.6".
我想使用包rand_pcg,但不知道版本。我怎样才能找到它?
【问题讨论】:
标签: rust dependencies version rust-cargo
Cargo.toml 文件要求我说明依赖项的版本,例如rand = "0.6".
我想使用包rand_pcg,但不知道版本。我怎样才能找到它?
【问题讨论】:
标签: rust dependencies version rust-cargo
导航到https://crates.io/,在搜索框中输入您的 crate 名称,然后查看版本。您也可以单击剪贴板图标复制完整的依赖项以添加到 Cargo.toml。
导航到https://docs.rs/,在搜索框中输入您的 crate 名称,然后查看版本。如果点击进入 crate,然后可以点击剪贴板图标复制完整的依赖项以添加到 Cargo.toml。
导航到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,它会输出依赖行。
【讨论】: