Organize a large Rust project by splitting code into multiple crates within a Cargo workspace.
- Create a workspace root directory and initialize it with
cargo init --name my-workspace. - Create a library crate for shared logic using
cargo new --lib core. - Create a binary crate for the executable using
cargo new --bin app. - Define the workspace members in the root
Cargo.tomlunder the[workspace]section. - Add the library crate as a dependency in the binary crate's
Cargo.tomlusingpath = "../core".
# Root Cargo.toml
[workspace]
members = ["core", "app"]
# app/Cargo.toml
[dependencies]
core = { path = "../core" }