Question about reexporting dependencies in the same project

Hello everyone,

I'm working on a (monolith) web service, the project itself is divided in sub crates in the root folder, each handling specific domain logic. Let's call them "domain crates". I also have a "core" crate that defines data types and functionality common to most of the domain crates. These domain crates have similar dependencies in their Cargo.toml file, for example all domain crates that need database acces, use sqlx as a dependency.
Currently, I make sure that all common dependencies are at the same version in Cargo.toml.

Question: Should I continue handling common deps this way or should reexport them from the "core" crate?

As always, it depends.

I would just add the common dependencies to the Cargo.toml for each crate and let cargo workspaces manage the versions. You probably don't need the extra level of indirection, and your sub-crates should be striving to have a low dependency count anyway.

Thank you for your answer.

I've forgotten how Cargo workspaces work and I'm embarrassed about it. Checking the docs on Cargo workspaces confirm that Cargo will handle dependency version in the workspace.

1 Like

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.