0

I am learning cargo (rust package manager). My code is working from console, but I can't apply dependency in VS code

My actions

1 Create project

cargo new hello_world

2 add rand library to the Cargo.toml

[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"

[dependencies]
rand = "0.6.5"
  

3 I can build and run my project via console

cargo build
cargo run

Problem I am run code via VS code. I am clicking 'run' button and see the following. (I don't have errors if run without. rand = "0.6.5" )

[Running] cd "/Users/mascai/root_folder/dev/projects/08_rust/01_test/hello_world/src/" && rustc main.rs && "/Users/mascai/root_folder/dev/projects/08_rust/01_test/hello_world/src/"main
error[E0433]: failed to resolve: use of undeclared crate or module `rand`
 --> main.rs:2:13
  |
2 |     let r = rand::random::<i32>();
  |             ^^^^ use of undeclared crate or module `rand`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.
 

P.S:

I am using MacOS, rust-analyzer extension was installed

VsCode Version: 1.68.1

cafce25
  • 15,907
  • 4
  • 25
  • 31
mascai
  • 1,373
  • 1
  • 9
  • 30

0 Answers0