Introduction
Cargo.toml is the manifest of a Rust package, read by
Cargo, Rust’s build tool and package
manager. It names the package, its version and the Rust edition it is written for, and
lists the crates (Rust libraries) it depends on, which Cargo downloads from crates.io
and builds. Cargo writes the exact versions it chose to Cargo.lock beside
it.
A manifest can also describe a workspace: several packages in one repository that share a lock file and build folder.
Structure
The file is written in TOML, a simple configuration format of tables in square
brackets and key = value lines. The [package] table gives the
name, version and edition, and optionally a
description, licence and authors. [dependencies] maps crate names to
version requirements, or to tables giving a version, a Git repository or a local path
and the optional features to turn on. Other tables include
[dev-dependencies], [features], [profile.release]
and [workspace].
[package]
name = "hello"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
rand = "0.8"
Also used for
Links
Software
- Cargo, installed with Rust by rustup (Windows, macOS, Linux)
- rust-analyzer, the language server used by most editors (Windows, macOS, Linux)
- RustRover (Windows, macOS, Linux)
Developers
- toml, Rust crates that read and write TOML, including
toml_edit, which keeps formatting
Reference
- The Manifest Format, The Cargo Book
- TOML, the configuration language’s specification