i have added dependency in cargo.toml but it is showing same error
how can i fix this issue ?
Can you show your Cargo.toml
? Do you have edition = "2021"
set properly?
Edit: On second look.. what is tempCodeRunnerFile.rs
?
This looks like a way of running code invented by VSCode that is fundamentally incompatible with …anything except simplest scripting languages!?
This vscode feature does not support Cargo, and does not support dependencies. It tries to run only selected code fragment without anything, no deps, no other functions, nothing. That is pretty useless in Rust. It will always fail when you try running anything besides most basic hello world.
tempcoderunnerfile.rs only has single line use rand
cargo.toml have 2021 edition but it is showing same error
The question was more of a "where is this file, how does it relate to the rest or your cargo project and how does it compile?" kind of question rather than just "what does it contain". @kornel's answer shed some light on it I suppose, though I can't say I fully understand it from that either. As @kornel's comment already suggested, it doesn't seem to be a concept / workflow thats compatible with Rust, and apparently especially it's incompatible with Rust projects with dependencies.
Thus you probably don't want that file. You'll want to be running your full cargo project with cargo run
as described by the book and that should work (or only complain about main.rs
as long as your project doesn't have other modules). If you want some IDE experience with vscode, then look into Rust Analyzer which should compile your rust project correctly, too.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.