Real Projects · 14 min · free with an account

Workspaces

Lesson preview · about 30%

A workspace builds several crates against one lockfile.

Core idea

Workspace members share one lockfile, so versions cannot diverge.

Start with the idea

Members share a target directory and lockfile, while the resolver may still select multiple versions of a dependency when requirements are incompatible. Splitting a project into a library plus a thin binary is the usual first move, because it makes the library testable on its own.

A Cargo workspace groups packages that are developed together. A root Cargo.toml lists members such as core and cli; the packages share a lockfile and build output directory, and workspace commands can operate across members. A common design puts reusable behavior in a library and keeps the binary thin: the CLI parses arguments, calls library functions, and prints a result. This makes the core easier to test and reuse.

The example's dependency path from cli to core is explicit in the CLI manifest.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Cargo & Real Projects