小编Nan*_*and的帖子

解决 Rust 中的导入问题

我在从crates.io导入rand crate时遇到问题。添加行 rand="0.8.3" 然后为项目运行命令Cargo build后,它不断显示相同的错误:

error[E0432]: unresolved import `rand`
 --> main.rs:1:5
  |
1 | use rand::Rng;
  |     ^^^^ maybe a missing crate `rand`?

error[E0433]: failed to resolve: use of undeclared crate or module `rand`
 --> main.rs:4:25
  |
4 |     let secret_number = rand::thread_rng().gen_range(1..=11);
  |                         ^^^^ use of undeclared crate or module `rand`

error: aborting due to 2 previous errors
Run Code Online (Sandbox Code Playgroud)

Cargo.toml文件​

[package]
name = "roller"
version = "0.1.0"
authors = ["User"]
edition = "2018"

# See more keys …
Run Code Online (Sandbox Code Playgroud)

rust rust-crates rust-cargo

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

rust ×1

rust-cargo ×1

rust-crates ×1