找不到rand依赖项
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.4.0"
尝试了不同的 rand = "0.4.0" 和 rand = "3.1.4"
写道:
C:\Dima\Rust\guessing_game1>cargo run
Updating crates.io index
Compiling winapi v0.3.9
error[E0432]: unresolved import `shared::basetsd`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\shared\minwindef.rs:8:13
|
8 | use shared::basetsd::{LONG_PTR, UINT_PTR};
| ^^^^^^^ could not find `basetsd` in `shared`
error[E0432]: unresolved import `shared::ntdef`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\shared\minwindef.rs:9:13
|
9 | use shared::ntdef::{HANDLE, LONG};
| ^^^^^ could not find `ntdef` in `shared`
error[E0432]: unresolved import `shared::basetsd`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\ntsecapi.rs:7:13
|
7 | use shared::basetsd::{ULONG64, ULONG_PTR};
| ^^^^^^^ could not find `basetsd` in `shared`
error[E0432]: unresolved import `shared::ntdef`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\ntsecapi.rs:10:13
|
10 | use shared::ntdef::NTSTATUS;
| ^^^^^ could not find `ntdef` in `shared`
error[E0432]: unresolved import `shared::sspi`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\ntsecapi.rs:11:13
|
11 | use shared::sspi::SecHandle;
| ^^^^ could not find `sspi` in `shared`
error[E0432]: unresolved import `um::lsalookup`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\ntsecapi.rs:12:9
|
12 | use um::lsalookup::{
| ^^^^^^^^^ could not find `lsalookup` in `um`
error[E0432]: unresolved import `um::subauth`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\ntsecapi.rs:15:9
|
15 | use um::subauth::{PUNICODE_STRING, STRING, UNICODE_STRING};
| ^^^^^^^ could not find `subauth` in `um`
error[E0432]: unresolved import `shared::basetsd`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\winnt.rs:9:13
|
9 | use shared::basetsd::{
| ^^^^^^^ could not find `basetsd` in `shared`
error[E0432]: unresolved import `shared::ktmtypes`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\winnt.rs:13:13
|
13 | use shared::ktmtypes::UOW;
| ^^^^^^^^ could not find `ktmtypes` in `shared`
error[E0432]: unresolved import `vc::excpt`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\winnt.rs:17:9
|
17 | use vc::excpt::EXCEPTION_DISPOSITION;
| ^^^^^ could not find `excpt` in `vc`
error[E0432]: unresolved import `vc::vcruntime`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\winnt.rs:18:9
|
18 | use vc::vcruntime::size_t;
| ^^^^^^^^^ could not find `vcruntime` in `vc`
error[E0432]: unresolved import `shared::ntdef`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\winnt.rs:151:17
|
151 | pub use shared::ntdef::LARGE_INTEGER;
| ^^^^^ could not find `ntdef` in `shared`
error[E0432]: unresolved import `shared::ntdef`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\winnt.rs:153:17
|
153 | pub use shared::ntdef::ULARGE_INTEGER;
| ^^^^^ could not find `ntdef` in `shared`
error[E0432]: unresolved import `shared::ntdef`
--> C:\Users\comp\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\winnt.rs:159:17
|
159 | pub use shared::ntdef::LUID;
| ^^^^^ could not find `ntdef` in `shared`
For more information about this error, try `rustc --explain E0432`.
error: could not compile `winapi` (lib) due to 14 previous errors
C:\Dima\Rust\guessing_game1>
我尝试手动添加兰特
C:\Dima\Rust\guessing_game1>cargo add rand
Updating crates.io index
Adding rand v0.4.0 to dependencies.
Features as of v0.4.1:
+ libc
+ std
- alloc
- i128_support
- nightly
C:\Dima\Rust\guessing_game1>cargo add alloc
Updating crates.io index
error: the crate `alloc` could not be found in registry index.
C:\Dima\Rust\guessing_game1>cargo add i128_support
Updating crates.io index
error: the crate `i128_support` could not be found in registry index.
C:\Dima\Rust\guessing_game1>cargo add nightly
Updating crates.io index
error: the crate `nightly` could not be found in registry index.
C:\Dima\Rust\guessing_game1>cargo add rand
Updating crates.io index
Adding rand v0.4.0 to dependencies.
Features as of v0.4.1:
+ libc
+ std
- alloc
- i128_support
- nightly
但由于某种原因它不支持库。
这是设置
这是答案,库版本中有错误,代码中需要添加点( gen_range (1..101) )
Cargo.toml
主程序.rs
结论