0Pricing
Learn Rust Coding · Lesson

Workspaces

Multi-crate projects.

Workspaces is a free Learn Rust Coding lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn Rust Coding learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is a Workspace?

A workspace is a set of related crates that share a single Cargo.lock and a common target directory. It's the standard way to manage multi-crate projects.

The Root Manifest

The workspace root has a Cargo.toml with a [workspace] table listing the member crates. The root itself usually has no package.

[workspace]
members = ["app", "core", "utils"]
resolver = "2"

Workspace Layout

A typical layout puts each crate in its own subdirectory:

  • Cargo.toml — workspace root
  • app/ — a binary crate
  • core/ — a library crate
  • utils/ — another library crate

Creating Members

You create members like any crate, then add them to the root manifest's members list.

cargo new app
cargo new core --lib
cargo new utils --lib

Depending on a Member

One member crate depends on another using a path dependency in its own Cargo.toml.

[dependencies]
core = { path = "../core" }
utils = { path = "../utils" }

Calling Across Crates

Public items in one crate are used from another by referencing the crate name. Here core exposes a function the binary calls.

// in core/src/lib.rs
pub fn greeting(name: &str) -> String {
    format!("Hello, {name}!")
}

// in app/src/main.rs
fn main() {
    let msg = core::greeting("workspace");
    println!("{msg}");
}

Building the Whole Workspace

Running Cargo at the root builds every member. The shared target directory means common dependencies are compiled only once.

cargo build
cargo test

Targeting One Member

Use -p (or --package) to run a command for a single member crate.

cargo run -p app
cargo test -p core

Workspace Dependencies

Define shared versions once under [workspace.dependencies], then reference them from members to keep versions in sync.

# root Cargo.toml
[workspace.dependencies]
serde = "1.0"

# member Cargo.toml
[dependencies]
serde = { workspace = true }

Why Use Workspaces?

Benefits of a workspace:

  • Single shared lockfile for consistent versions
  • Faster builds via one shared target directory
  • Easy to split a large project into focused crates
  • One command builds and tests everything

Excluding a Directory

The exclude key keeps certain directories out of the workspace, while default-members sets which crates run when you do not pass -p.

[workspace]
members = ["app", "core"]
exclude = ["experiments"]
default-members = ["app"]

Quick Check

What do all crates in a workspace share?

Recap

You learned about workspaces:

  • The [workspace] table lists members
  • Members depend on each other via path
  • A shared lockfile and target directory speed up builds
  • Use -p to target one member
  • [workspace.dependencies] centralizes versions

Frequently asked questions

Is the “Workspaces” lesson free?

Yes — the full text of “Workspaces” is free to read here on the web, and the Learn Rust Coding course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn Rust Coding course, upgrade to CoddyKit PRO.

What will I learn in “Workspaces”?

Multi-crate projects. You practise Learn Rust Coding with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Learn Rust Coding?

No prior experience is required. Learn Rust Coding on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Workspaces” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Learn Rust Coding lesson?

Yes. Every Learn Rust Coding lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Cargo Basics
  2. Cargo.toml
  3. Workspaces
  4. Features and Profiles
← Back to Learn Rust Coding