Cargo is Rust’s package manager and build system. It creates project structure, compiles and runs programs, manages dependencies, links crates, and supports package publication. section 2.1 section 3.2.1
Common Cargo tasks include:
- Create an application or library with cargo new. section 2.1 section 4.1
- Compile and execute an application with cargo run. section 2.1
- Compile a crate and its dependencies with cargo build. section 3.2.1
- Declare package metadata, the Rust edition, and dependencies in Cargo.toml. section 3.2.1
Adding libc to a crate
Add libc under [dependencies] in Cargo.toml, then run cargo build. Cargo updates the crates.io index, downloads and compiles the requested version, and links it without a separate compiler-flag step. section 3.2.1
$ cargo new art-museum
A minimal command creates an art-museum project with the files needed to begin writing Rust. section 2.1
Listing 3.3 Default Cargo configuration file
[package] name = "calculate" version = "0.1.0" authors = ["You <you@you.com>"] edition = "2018" # See more keys and their definitions at # https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies]
The generated Cargo.toml records package identity, version, authors, edition, and an initially empty dependency table. section 3.2.1




