Не может найти зависимость rand

Не может найти зависимость 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>

попробовал руками добавить rand

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

но почему-то не тянет библиотеки.


вот установки

введите сюда описание изображения


Ответы (1 шт):

Автор решения: timob256

вот ответ , ошибка в версии библиотеки и в коде на до было точечки добавить ( gen_range (1..101) )

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.5"

main.rs

use std::io;
use rand::Rng;

fn main() {
  println!("Угадайте число!");

 let secret_number = rand::thread_rng().gen_range (1..101);

 println!("Пожалуйста, введите свою догадку.");

 let mut guess = String::new();

  io::stdin().read_line(&mut guess).expect("Не получилось прочитать строку");

  println!("Вы загадали: {}", guess);
}

вывод

C:\Dima\Rust\guessing_game>cargo run
warning: unused variable: `secret_number`
 --> src\main.rs:7:6
  |
7 |  let secret_number = rand::thread_rng().gen_range (1..101);
  |      ^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_secret_number`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: `guessing_game` (bin "guessing_game") generated 1 warning (run `cargo fix --bin "guessing_game"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target\debug\guessing_game.exe`
Угадайте число!
Пожалуйста, введите свою догадку.
32
Вы загадали: 32
→ Ссылка