I have a Rust project that is composed of several utilities splited in 3 different crates with some dependencies between them. The directory tree would be as follows:
|_ CrateA
| |_lib.rs
| |_cargo.toml
|_ CrateB
| |_lib.rs
| |_cargo.toml
|_ CrateC
| |_lib.rs
| |_cargo.toml
I'd like to publish this whole project as a single crate (let's call it GlobalCrate), allowing anybody that uses it to access the public funcionality contained in any of those crates. For example, one application importing this "GlobalCrate" should be able to perform the following calls:
fn main()
{
GlobalCrate::CrateA::functionA();
GlobalCrate::CrateB::functionB();
GlobalCrate::CrateC::functionC();
}
Is this possible or do I have to publish each crate separately and then import all of them on my application?
Yes, you can create
global_cratethat just re-exports the other crates contents:and in
global_crate/Cargo.toml:Note: The
versionkey in that table is not optional if you want to publish this crate.You do have to publish all the crates
global_cratedepends on in addition toglobal_crateitself though.