liveBook · Manning

Cargo.toml

As explained in Rust in Action: Systems programming concepts and techniques

Cargo.toml is a Rust package manifest that declares project metadata and dependencies.

Cargo.toml is the manifest at the root of a Rust project. It records package metadata and dependencies, while Cargo uses it to coordinate compilation and produce executables. section 1.3.1 section 2.15

A project manifest

A small command-line project can declare its identity and libraries like this: [package] name = "clock", version = "0.1.1", authors = ["Tim McNamara <author@rustinaction.com>"], edition = "2018"; [dependencies] chrono = "0.4", clap = "2". Cargo reads these declarations when building the program. section 9.6.4

Common manifest sections describe different parts of a project:

  • [lib] selects library metadata and a source path, while repeated [[bin]] sections define executable names and source paths. section 7.5.2

Cargo.toml works with the generated project structure: source files normally live in src, while Cargo manages build artifacts in target. After a build, Cargo.lock records exact dependency versions so later builds remain reproducible until the manifest changes. section 1.3.1

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Explains manifest structure through complete examples, but stops short of comprehensive Cargo configuration reference.
Examples
Uses Hello World, an in-memory key-value store, a clock command-line tool, and an operating-system project.
What you can do after
Operate/configure Cargo by declaring package metadata, dependencies, libraries, and executable targets.
How it connects
Connects package metadata and dependencies with Cargo, Cargo.lock, crates, library targets, binary targets, and compilation.

Also explained in

Compare how 4 books explain cargo.toml →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.