I have an issue with cargo commands. When I do "cargo new example" it is created but i cannot run it since it's looking for .toml file in a wrong directory and i dont know the reason why. Also can't run "cargo clean"
As you can see I am cd in a different folder and it's looking for something in files that don't even exist anymore. I have tried a lot of things even reinstalling rust.
First, Cargo thinks you have some already-existing workspaceCargo.toml file, perhaps located in rust_projects or in delete. The error you got from cargo new is because that workspace manifest refers to rust/ledBlink. You should probably delete that file (after examining its contents) because it is not usually a good idea to put all of your Rust code in one workspace (workspaces are best used for actually related code that shares dependencies). But if you want to keep it, then modify it to remove ledBlink from the members list — that will fix the error.
Second, note that it is expected that the sequence
cargo new project_name
cargo run
will not succeed, because cargo new creates a package in a new subdirectory, and cargo run and cargo clean need to be run from inside that subdirectory, and will fail if not inside some package or workspace. This should work (once the workspace is removed or fixed):
cargo new project_name
cd project_name
cargo run
You can also use cargo init to create the files in the current directory instead. (Usually you would do that in an empty directory you created.)
The problem is that it thinks I have some already-existing workspace even though that path doesn't even exist. I have deleted all files and only have one project called "hello". Whatever I try to do it leads me to the wrong path (it thinks there is a workspace somewhere where it can't be because I have deleted that path already). Any ideas ?
Folder ledBlink does not exist, of course, that's (almost) exactly what Cargo says. Do you have hidden files being hidden in Explorer? What do you get if you cd to Desktop in your command prompt and do dir /a?
Check every one of those places, find where that file is, and delete it (after checking its contents to make sure it's not anything you wanted to keep).
Cargo really should specify where the workspace root is in its messages. Currently, in cases like this, it amounts to saying: "I can't do that because something is wrong. Somewhere. Good luck!"
Cargo can tell you where your workspace's Cargo.toml file is.
For example, I have a repository called wai in my ~/Documents folder which has a workspace with several crates. By default, the cargo locate-project command will tell you where the Cargo.toml for the "current" crate is.
$ cd ~/Documents/wai/crates/language-server
$ cargo locate-project
{"root":"/Users/michael/Documents/wai/crates/language-server/Cargo.toml"}
In your case, if you ran it inside C:\Users\Peter\Desktop\delete\rust\ledBlink\hello, it'd be the hello directory.
However if you add the --workspace flag, it'll tell you which workspace it thinks your current crate belongs to.
Daaaaaaamn. For some reason when looking this up online I thought locate-project was a crate you had to install separately. I think its because of the dash between the two words, as this is often present in the names of cargo crates, like cargo-add for example.
the thing is that location C:\Users\Peter\Desktop\delete\rust\ledBlink\hello does not exist since directory "rust" has been deleted a while ago. For some reason it's still looking for a worskpace in that place.
I have also deleted rust and everything it belongs to it for a second time now, still nothing changes.
When I did "rustup self uninstall" it didn't delete everything, but when I did it manually like you suggested and deleted all the cargo folders that did the trick. Thank you sir!