无法为要求 `rand = "^0.9.0"` 选择版本

Adw*_*ash 10 rust rust-cargo

我每次运行时都会收到此错误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)`
Run Code Online (Sandbox Code Playgroud)

Cargo.toml看起来像这样:

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)`
Run Code Online (Sandbox Code Playgroud)

小智 9

这个错误是因为没有0.9.0可用的版本而导致的。将其更新为0.8.0. 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.8.0"
Run Code Online (Sandbox Code Playgroud)


小智 7

我自己也经历过这一点,我相信这种困惑源于Rust 教程中提到 0.9.0 作为理解升级 Rust 箱子的例子。

我不确定他们为什么选择这个例子,因为它不存在。如果您是 Rust 新手并且想要尝试升级 Rust 包,那么将 0.7.x 升级到 0.8.0 是一个更好的主意。


Cal*_*ius 6

出现此类错误的另一个可能原因是您的编译器已过时,并且新版本的库针对的是新编译器。使用 更新您的工具链rustup update

我有一个使用 clap 4.2 的项目,但它拒绝在另一台计算机上编译,并出现这样的错误。