未能为要求选择一个版本`rand ='^0.9.0;
我每次运行货物构建
:
error: failed to select a version for the requirement `rand = "^0.9.0"`
candidate versions found which didn't match: 0.8.5, 0.8.4, 0.8.3, ...
location searched: crates.io index
required by package `guessing_game v0.1.0 (D:\Adwait\Rust\project\guessing_game)`
cargo.toml
看起来像这样的错误,我会遇到此错误。
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.9.0"
I am getting this error every time while running cargo build
:
error: failed to select a version for the requirement `rand = "^0.9.0"`
candidate versions found which didn't match: 0.8.5, 0.8.4, 0.8.3, ...
location searched: crates.io index
required by package `guessing_game v0.1.0 (D:\Adwait\Rust\project\guessing_game)`
Cargo.toml
looks like this:
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.9.0"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于没有版本
0.9.0
可用,因此引起了此错误。将其更新为0.8.0
。货物toml应该看起来像这样。This error is caused because there is no version
0.9.0
available. Update it to0.8.0
. Cargo.toml should look like this.我自己经历了这个,我相信这种混乱是源于关于Rust的教程提及0.9.0作为了解升级锈蚀箱的一个例子。
我不确定他们为什么选择这个例子,因为它不存在。如果您是Rust的新手,并且想使用升级的Rust Crate,则可以将0.7.x升级到0.8.0是一个更好的主意。
I experienced this myself, I believe the confusion is stemming from the tutorial on Rust mentioning 0.9.0 as an example to understand upgrading Rust crates.
I'm not sure why they chose that example, since it doesn't exist. Would be a better idea to do 0.7.x being upgraded to 0.8.0 if you're new to Rust and want to play around with upgrading Rust crates.
遇到这样的错误的另一个可能原因是,您的编译器已过时,新版本的库针对新编译器。使用
Rustup Update
更新工具链。我有一个使用拍手4.2的项目,但拒绝在另一台计算机上编译,其中有这样的错误。
Another possible reason for getting an error like this is that your compiler is outdated and the new version of the library targets the new compiler. Update your toolchain with
rustup update
.I have a project that used clap 4.2, but which refused to compile on another computer with an error like this.
我只是一个初学者学习Rust的人,但是从我所看到的,如果您使用
货物搜索rand
您获得了此输出:如您所见,“ 0.9.0”是Beta版本,这就是为什么它会给您错误。如果您仍然想使用它,则可以在cargo.toml文件中编写
rand = {version =“ 0.9.0-beta.1”}
。如果您只想最新的稳定版本RAND(或任何其他依赖关系,从我到现在为止),则可以使用
货物添加rand
,它将自动添加“ 0.8.5”货物文件的版本。如果出于某种原因,您想手动添加它们,则可以使用
货物信息rand
,这将为您提供此输出:然后,您可以将输出中看到的版本添加到cargo.toml文件。
I'm just a beginner learning Rust, but from what I've seen, if you use
cargo search rand
you get this output:As you can see, the "0.9.0" is a beta version, which is why it gives you the error. If you still want to use it, you can write
rand = { version = "0.9.0-beta.1" }
in the Cargo.toml file.If you just want the latest stable version of rand (or any other dependency, from what I've seen up until now), you can use
cargo add rand
which will automatically add the "0.8.5" version to the Cargo.toml file.If, for some reason, you want to add them manually, you can use
cargo info rand
, which will give you this output:Then you can add the version you see in the output to the Cargo.toml file.