Cargo.toml
Manifest and dependencies.
Cargo.toml is a free Learn Rust Coding lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn Rust Coding learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Manifest
Cargo.toml is the manifest file at the root of every Rust project. It describes the package and its dependencies using the TOML format.
The [package] Section
The [package] table holds metadata about your crate.
name— the crate nameversion— semantic versionedition— the Rust edition (e.g. 2021)
[package]
name = "my_app"
version = "0.1.0"
edition = "2021"Adding Dependencies
List external crates under [dependencies]. Cargo downloads them from crates.io and compiles them for you.
[dependencies]
rand = "0.8"
serde = "1.0"cargo add
Instead of editing the file by hand, use cargo add to insert a dependency with the latest compatible version.
cargo add rand
cargo add serdeVersion Requirements
Version strings use semver rules:
"1.0"means >=1.0.0 and <2.0.0 (caret by default)"=1.2.3"pins an exact version"~1.2"allows patch updates only
[dependencies]
regex = "=1.10.2"
log = "~0.4"Using a Dependency
Once added, bring items into scope with use and call them in code. Here we use the rand crate (in a real project).
use rand::Rng;
fn main() {
let mut rng = rand::thread_rng();
let n: u8 = rng.gen_range(1..=6);
println!("Rolled a {n}");
}Dependency Features
Many crates expose optional features. Enable them with the features key, often disabling defaults first.
[dependencies]
serde = { version = "1.0", features = ["derive"] }Dev Dependencies
[dev-dependencies] are only compiled for tests, examples, and benchmarks — never shipped with your library.
[dev-dependencies]
pretty_assertions = "1.4"Path and Git Dependencies
Dependencies can also come from a local path or a git repository instead of crates.io.
[dependencies]
my_lib = { path = "../my_lib" }
some_crate = { git = "https://github.com/user/repo" }Updating Dependencies
cargo update bumps dependencies to the newest versions allowed by your version requirements and rewrites Cargo.lock.
cargo updateOptional Package Metadata
The [package] table accepts extra fields that show up on crates.io when you publish:
authors— who wrote itdescription— a short summarylicense— an SPDX identifier likeMITrepository— the source URL
[package]
name = "my_app"
version = "0.1.0"
edition = "2021"
description = "A small demo crate"
license = "MIT"Quick Check
Where should a crate that is only needed when running tests be listed?
Recap
You explored the manifest:
[package]holds metadata like name, version, edition[dependencies]declares crates from crates.io, path, or git- Version strings follow semver rules
featuresenable optional functionality[dev-dependencies]are test-only
Frequently asked questions
Is the “Cargo.toml” lesson free?
Yes — the full text of “Cargo.toml” is free to read here on the web, and the Learn Rust Coding course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn Rust Coding course, upgrade to CoddyKit PRO.
What will I learn in “Cargo.toml”?
Manifest and dependencies. You practise Learn Rust Coding with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Learn Rust Coding?
No prior experience is required. Learn Rust Coding on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Cargo.toml” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Learn Rust Coding lesson?
Yes. Every Learn Rust Coding lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.