Cargo.toml is the manifest for a Cargo project. It holds package details, such as the name, version, and Rust edition, and has a [dependencies] section for external crates—code your project uses from elsewhere. Running cargo new my_project creates this file alongside a src directory for your code. section 16.5.1 section 18.1.1
[package] name = "rust_book" version = "0.1.0" authors = ["David MacLeod"] edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] rand = "0.8.5"
This manifest adds rand = "0.8.5" under [dependencies]. The quoted value specifies the version used in this example. section 16.5.1
To add a crate, find it on crates.io and copy its suggested line into [dependencies]. You can also run cargo add rand. Then cargo run builds and runs the project: Cargo brings in rand and the other crates rand needs. In code, paths into this crate begin with rand rather than std. section 16.5.1 section 18.1.1
A release-mode setting
Cargo.toml can hold settings beyond dependencies. Adding [profile.release] followed by panic = 'abort' selects abort behavior for a release build. Use cargo run --release or cargo build --release to build with that setting; it can make the binary a little smaller, but is not usually the desired panic behavior. section 21.2



