Hey everyone, I'm having rust newbie questions here about the organization.
Is it a thing to have a project with multiple Cargo.toml? Therefore multiple different subfolders with their own src folder and Cargo.toml and one Cargo file at the root?
How do we manage the dependencies then? If I want to install tokio (that is used in all my packages), should I install it in the root Cargo? Or in each package?
If I need to add the dependency for each package, how about rust-analyzer how can I configure it to look into the sub-Cargo?
Hope my questions are clear enough.
Any lead or reference to good reads would also be great thank you very much
I want to clarify that while you need to explicitly add dependencies to each package, you can keep the version requirements and features centralised in the workspace.
To do this, declare dependencies in the root Cargo.toml, then use dependency_lib.workspace = true syntax in the individual packages' Cargo.toml files.
In my opinion it is best to manage dependency version in the workspace Cargo.toml, but features in crate-level Cargo.toml.
This allows to have a better answers to the question "do we really need this feature" for each crate specifically, and thereby reduce compilation times.
Keeping the version only in the workspace Cargo.toml is useful to have only one place to change when we need to upgrade, and also it makes it possible to reuse a crate in several workspaces without having a dependency hell.