Managing multiple sub-projects in a project without errors

Hi Rust Community,
I am a newbie. I am facing a problem when I create multiple projects in a project. Right now Rust analyzer gives me different errors when trying to solve one problem. The problem is due to multiple Cargo.toml files. Sometimes it gave me dependency errors sometimes it gave me conflicting or workspace errors.
Can someone provide me with a template to manage multiple projects where each project have their own dependencies versions and workspace. Or give me guidelines on how to manage projects efficiently


I'd change your directory structure such that your packages are not nested. I.e. instead of having two packages foo and bar where bar lives in ./foo/bar, move it to the top-level of your project ./bar. That way you avoid any workspace problems completely. If that's not feasible, make sure every package has their own workspace by adding an empty [workspace] table to your nested packages. I.e. in your ./foo/bar/Cargo.toml add this line:


The problem I am encountering in the pub-sub project
Actually, rust is a folder in a root where root Cargo.toml exists which is not shown in below tree. If I exclude pub-sub all project works fine.

Root Cargo.toml

resolver = "2"

members = ["rust/*"]

exclude = ["typescript", "rust/scripts"]

That's probably because publisher and subscriber aren't part of your workspace. If you want to add every package in the rust directory and every subdirectory to your top-level workspace, I think you can just change the members from rust/* to rust/**/*.

The Cargo.toml in pub-sub looks suspiciously superfluous by the way, based on your tree. What does it contain? If you are trying to nest workspaces, i.e. have pub-sub be its own workspace inside your global one, AFAIK that's not possible.

Even if I remove Cargo.toml in pub-sub the issue persists
You can check the repo

Indeed. The recommendation with members = ["rust/**/*"] did not work. Instead I had to manually add "rust/pub-sub/*" to the members and excluded "rust/pub-sub" itself. I've created a PR in your repo with these fixes.

1 Like

Thanks, it resolves the issue.

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.