Skip to content

Cargo and Ecosystem

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
## Intuition

Cargo is Rust’s build system and package manager, handling compilation, dependency resolution, and publishing. Crates.io hosts the ecosystem with semantic versioning. Workspaces enable monorepo structures. Cargo features allow conditional compilation, and build scripts handle code generation. The ecosystem’s emphasis on small, composable crates means most functionality comes from libraries rather than the standard library, making dependency management a core skill.

  • [[rust/05-traits-generics/traits-and-generics]] - Trait conventions in the ecosystem
  • [[rust/04-error-handling/error-handling]] - Error handling crate conventions
  • [[rust/06-concurrency/concurrency]] - Async runtime ecosystem
  • [[rust/03-structs-enums/structs-and-enums]] - Derive macros for common traits