Rust Lang Analyzer Not Working

Hello I am new to Rust and currently learning it in my spare time. The problem is I have a folder where I list all my codes in an organized way created by "cargo new --bin example". And when I open the workspace in VSCode rust lang analyzer does not work for some projects. I searched a bit and I think I need to add cargo toml files to "rust-analyzer.linkedProjects" in extension settings. But when I do that, it works on some projects but doesn't work for others.

 "rust-analyzer.linkedProjects": [
        "C:/Users/user/Desktop/VSC/Rust/tutorials/rectangles/Cargo.toml",
        "C:/Users/user/Desktop/VSC/Rust/tutorials/branches/Cargo.toml",
        "C:/Users/user/Desktop/VSC/Rust/tutorials/guessing_game/Cargo.toml",
        "C:/Users/user/Desktop/VSC/Rust/tutorials/hello_cargo/Cargo.toml",
        "C:/Users/user/Desktop/VSC/Rust/tutorials/ownership/Cargo.toml",
        
    ]
+---Rust/tutorials(workspace)
|   |   
|   |
|   +---Guessin Game
|   |   |   Cargo.toml
|   |   |
|   |   \---src
|   |           main.rs
|   |
|   \---Branches
|       |   Cargo.toml
|       |
|       \---src
|               main.rs
|

(other 3 project with same template)

Why doesn't it work? Also I tried to add "C:/Users/user/Desktop/VSC/Rust/tutorials/./Cargo.toml" while commenting others out. It behaves strangely and continue to work with already working projects and vice versa. Can we do something like that?

When you say workspace, do you mean a Cargo workspace? RA supports these workspaces correctly. I have never had to configure RA for sub-packages in my workspaces.

The workspace (Rust/tutorials/Cargo.toml) just needs to include all of the sub-packages in its workspace.members list.

[workspace]
members = [
    "rectangles",
    "branches",
    "guessing_game",
    "hello_cargo",
    "ownership",
]

I used workspace to refer VSCode workspace. When I load my workspace folder (all these projects inside it as children folders) There is no "Cargo.toml" file directly inside Rust/tutorials/. Thus Rust Analyzer was raising an error "Cargo.toml file must be in the root folder".

That's right, you need a Cargo workspace (a Cargo.toml in your VSC workspace with workspace.members set accordingly). Otherwise Cargo (and Rust Analyzer) does not know how to find your packages. So, write one. Or copy the one from my previous reply.

That worked thanks. I thought cargo files are project-specific.