Skip to content
Tutorials Center
My learning

Topics

Rust Reference ยท Tools

Cargo.toml manifest

Reference for Cargo.toml: the package table, dependencies, features, targets, lints and metadata fields, with a runnable parser that shows how the format works.

Cargo.toml is the manifest of a Rust package, written in TOML. It names the package, lists its dependencies, declares build targets, features, profiles and lint levels, and holds the metadata used when publishing. Cargo reads it for every command.

The file has tables ([package], [dependencies]) holding key = value pairs. This page is a read-only reference for the fields; the examples parse a tiny manifest in plain Rust to show the structure.

TOML
[package]
name = "demo"
version = "0.1.0"
edition = "2024"

[dependencies]
serde = { version = "1", features = ["derive"] }

Try it

Rust Parsing a tiny manifest

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with io::stdin().read_line()), it gets the next line from this box.

Rust Package metadata at compile time

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with io::stdin().read_line()), it gets the next line from this box.

Syntax

Table / key Description
[package] name, version, edition Required identity of the package; edition picks the language edition ("2024").
description, license, repository, readme, keywords, categories Metadata shown on crates.io; description and license are required to publish.
rust-version Minimum supported Rust version.
[dependencies], [dev-dependencies], [build-dependencies] Crates for the library/binaries, tests and examples, and build.rs.
[target.'cfg(windows)'.dependencies] Platform-specific dependencies.
[features] Named optional capabilities, each a list of other features or dep:name entries.
[lib], [[bin]], [[example]], [[test]], [[bench]] Configure or add targets (path, name, harness, required-features).
[profile.*] Compiler settings, see Cargo profiles and features.
[workspace] Turns the package into a workspace root, see Cargo workspaces.
[lints] Lint levels, for example [lints.rust] unsafe_code = "forbid".

A dependency can be a string ("1.2"), or a table with version, path, git, branch, features, default-features, optional, package (rename) and workspace = true.

Usage notes

  • A bare version like "1.2" is a caret requirement: compatible updates up to, but excluding, 2.0.0.
  • Keys can use dotted form (serde.version = "1") or inline tables; both are valid TOML and mean the same.
  • Cargo discovers src/main.rs, src/lib.rs, src/bin/*.rs, examples/, tests/ and benches/ automatically. Set autobins = false and friends only if you need explicit control.
  • Unknown keys produce warnings, not errors, which catches typos in key names.
  • edition affects only your own crate; crates of different editions link together freely.
  • Never put secrets in the manifest. It ships in the published archive.
  • Use cargo add rather than hand-editing when you can; see cargo add, remove and update.