Skip to content

Cargo and Ecosystem | Rust - Wyatt's Notes

Cargo.toml is the manifest file that defines everything about your Rust project. It uses TOML Format:

[package]
name = "my_crate"
version = "0.1.0"
edition = "2024"
authors = ["Your Name <you@example.com>"]
description = "A short description"
license = "MIT"
repository = "https://github.com/user/my_crate"
keywords = ["example", "tool"]
categories = ["command-line-utilities"]
readme = "README.md"
rust-version = "1.75"
[dependencies]
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
clap = { version = "4", features = ["derive"] }
[dev-dependencies]
proptest = "1"
criterion = "0.5"
[build-dependencies]
cc = "1"
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
strip = true
[profile.dev]
opt-level = 0
debug = true
FieldPurpose
nameCrate name (must match ^[a-zA-Z0-9_-]+$)
versionSemVer version (e.g., 0.1.0``1.2.3-beta.1)
editionRust edition (2015``2018``2021``2024)
rust-versionMinimum supported Rust version (MSRV)
licenseSPDX license identifier (MIT``Apache-2.0``GPL-3.0)
repositorySource code URL
readmePath to README file
categoriescrates.io categories (max 5)

Workspaces allow you to manage multiple related crates in a single repository:

my-project/
├── Cargo.toml # workspace root
├── crates/
│ ├── core/
│ │ ├── Cargo.toml
│ │ └── src/
│ ├── cli/
│ │ ├── Cargo.toml
│ │ └── src/
│ └── server/
│ ├── Cargo.toml
│ └── src/
└── target/
[workspace]
resolver = "2"
members = [
"crates/core",
"crates/cli",
"crates/server",
]
[workspace.package]
version = "0.1.0"
edition = "2024"
license = "MIT"
repository = "https://github.com/user/my-project"
[workspace.dependencies]
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
thiserror = "2"
anyhow = "1"
[workspace.lints.clippy]
unwrap_used = "warn"
expect_used = "warn"

Each member crate inherits from the workspace:

## crates/core/Cargo.toml
[package]
name = "my-core"
version.workspace = true
edition.workspace = true
license.workspace = true
[dependencies]
serde.workspace = true
thiserror.workspace = true
Terminal window
cargo build # build all workspace members
cargo build -p my-core # build specific member
cargo test --workspace # test all members
cargo test -p my-core # test specific member
cargo run -p my-cli # run specific binary
cargo tree -p my-server # dependency tree for member
cargo metadata --format-version 1 # machine-readable workspace metadata
flowchart TD
    A[Cargo And Ecosystem] --> B[Key Concepts]
    A --> C[Core Principles]
    A --> D[Practical Applications]
    B --> E[Fundamental definitions]
    C --> F[Design patterns]
    D --> G[Real-world usage]

Cargo is Rust’s project manager, build system, and dependency registry rolled into one. Think of it as a chef who handles the recipe (Cargo.toml), the ingredients (dependencies from crates.io), and the cooking (compilation). The manifest file tells Cargo what to build, what dependencies to fetch, and how to optimise the output. Workspaces let you organise related crates in a monorepo, and profiles control the trade-off between compilation speed and runtime performance. Cargo is the toolchain that makes Rust’s ecosystem cohesive and productive.