cargo add is a Cargo command for adding an external crate dependency to a Rust package's Cargo.toml file. section 16.5.1
Adding rand
From a Cargo project, run cargo add rand. Cargo adds rand under [dependencies]. The next cargo run downloads the needed code and makes the crate available to the program. section 16.5.1 section 18.1.2
[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"
Shows the Cargo.toml dependency entry produced for rand. section 16.5.1

