未能为要求选择一个版本`rand ='^0.9.0;

发布于 2025-02-04 18:46:26 字数 626 浏览 4 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蓦然回首 2025-02-11 18:46:26

由于没有版本0.9.0可用,因此引起了此错误。将其更新为0.8.0。货物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"

This error is caused because there is no version 0.9.0 available. Update it to 0.8.0. Cargo.toml should look 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.8.0"
你的往事 2025-02-11 18:46:26

我自己经历了这个,我相信这种混乱是源于关于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.

回眸一遍 2025-02-11 18:46:26

遇到这样的错误的另一个可能原因是,您的编译器已过时,新版本的库针对新编译器。使用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.

春庭雪 2025-02-11 18:46:26

我只是一个初学者学习Rust的人,但是从我所看到的,如果您使用货物搜索rand您获得了此输出:

username@PC:~/Projects/guessing_game$ cargo search rand
rand = "0.9.0-beta.1"        # Random number generators and other randomness functionality. 
bevy_rand = "0.8.0"          # A plugin to integrate rand for ECS optimised RNG for the Bevy game engine.
tinyrand = "0.5.0"           # Lightweight RNG specification and several ultrafast implementations in Rust.
rand-construct = "0.10.0"    # Encapsulates the random-constructible and random-constructible-derive crates which are used for cr…
random_derive = "0.0.0"      # Procedurally defined macro for automatically deriving rand::Rand for structs and enums
tera-rand = "0.2.0"          # A suite of random data generation functions for the Tera template engine
tera-rand-cli = "0.2.0"      # A CLI tool for generating a feed of random data from a Tera template
rands = "0.8.8"              # Random number generators and other randomness functionality. 
faker_rand = "0.1.1"         # Fake data generators for lorem ipsum, names, emails, and more
rand_derive2 = "0.1.21"      # Generate customizable random types with the rand crate
... and 1581 crates more (use --limit N to see more)
note: to learn more about a package, run `cargo info <name>`

如您所见,“ 0.9.0”是Beta版本,这就是为什么它会给您错误。如果您仍然想使用它,则可以在cargo.toml文件中编写rand = {version =“ 0.9.0-beta.1”}

如果您只想最新的稳定版本RAND(或任何其他依赖关系,从我到现在为止),则可以使用货物添加rand,它将自动添加“ 0.8.5”货物文件的版本。

如果出于某种原因,您想手动添加它们,则可以使用货物信息rand,这将为您提供此输出:

username@PC:~/Projects/guessing_game$ cargo info rand
rand #random #rng
Random number generators and other randomness functionality.
version: 0.8.5 (latest 0.9.0-beta.1)
license: MIT OR Apache-2.0
rust-version: unknown
documentation: https://docs.rs/rand
homepage: https://rust-random.github.io/book
repository: https://github.com/rust-random/rand
crates.io: https://crates.io/crates/rand/0.8.5
features:
 +default       = [std, std_rng]
  alloc         = [rand_core/alloc]
  getrandom     = [rand_core/getrandom]
  libc          = [dep:libc]
  rand_chacha   = [dep:rand_chacha]
  std           = [rand_core/std, rand_chacha/std, alloc, getrandom, libc]
  std_rng       = [rand_chacha]
  log           = [dep:log]
  min_const_gen = []
  nightly       = []
  packed_simd   = [dep:packed_simd]
  serde         = [dep:serde]
  serde1        = [serde, rand_core/serde1]
  simd_support  = [packed_simd]
  small_rng     = []
note: to see how you depend on rand, run `cargo tree --invert --package [email protected]`

然后,您可以将输出中看到的版本添加到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:

username@PC:~/Projects/guessing_game$ cargo search rand
rand = "0.9.0-beta.1"        # Random number generators and other randomness functionality. 
bevy_rand = "0.8.0"          # A plugin to integrate rand for ECS optimised RNG for the Bevy game engine.
tinyrand = "0.5.0"           # Lightweight RNG specification and several ultrafast implementations in Rust.
rand-construct = "0.10.0"    # Encapsulates the random-constructible and random-constructible-derive crates which are used for cr…
random_derive = "0.0.0"      # Procedurally defined macro for automatically deriving rand::Rand for structs and enums
tera-rand = "0.2.0"          # A suite of random data generation functions for the Tera template engine
tera-rand-cli = "0.2.0"      # A CLI tool for generating a feed of random data from a Tera template
rands = "0.8.8"              # Random number generators and other randomness functionality. 
faker_rand = "0.1.1"         # Fake data generators for lorem ipsum, names, emails, and more
rand_derive2 = "0.1.21"      # Generate customizable random types with the rand crate
... and 1581 crates more (use --limit N to see more)
note: to learn more about a package, run `cargo info <name>`

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:

username@PC:~/Projects/guessing_game$ cargo info rand
rand #random #rng
Random number generators and other randomness functionality.
version: 0.8.5 (latest 0.9.0-beta.1)
license: MIT OR Apache-2.0
rust-version: unknown
documentation: https://docs.rs/rand
homepage: https://rust-random.github.io/book
repository: https://github.com/rust-random/rand
crates.io: https://crates.io/crates/rand/0.8.5
features:
 +default       = [std, std_rng]
  alloc         = [rand_core/alloc]
  getrandom     = [rand_core/getrandom]
  libc          = [dep:libc]
  rand_chacha   = [dep:rand_chacha]
  std           = [rand_core/std, rand_chacha/std, alloc, getrandom, libc]
  std_rng       = [rand_chacha]
  log           = [dep:log]
  min_const_gen = []
  nightly       = []
  packed_simd   = [dep:packed_simd]
  serde         = [dep:serde]
  serde1        = [serde, rand_core/serde1]
  simd_support  = [packed_simd]
  small_rng     = []
note: to see how you depend on rand, run `cargo tree --invert --package [email protected]`

Then you can add the version you see in the output to the Cargo.toml file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文