Cargo is Rust's package manager and build tool. In practical beginner terms: it creates projects, downloads libraries you depend on, asks Rust to compile your code, runs programs, runs tests, and keeps the project metadata in one predictable place.
Why does Cargo exist at all?
A single Rust file can be compiled directly with rustc. Real projects quickly become more complicated: several files, external libraries, build options, tests, different build modes, and dependency versions.
Cargo gives those moving parts a standard workflow. Instead of hand-building a different compiler command for every project, you describe the project and then use stable commands such as cargo build,cargo run, and cargo test.
Cargo.toml is the project manifest
A new Cargo project includes a file named Cargo.toml. It is written in TOML and tells Cargo important facts about the package.
[package] name = "hello-rust" version = "0.1.0" edition = "2024" [dependencies]
The [package] section describes your package. The [dependencies] section is where external Rust packages are declared when the project starts using them.
Package, crate, dependency: three words you will see a lot
A Cargo-managed project described by a Cargo.toml manifest.
A Rust compilation unit. A package contains at least one crate and can contain binary and library crates.
Another package your project uses instead of implementing that functionality itself.
The Rust community package registry Cargo can use to obtain published dependencies.
The distinction becomes useful when projects grow. At the beginning, it is enough to know that Cargo manages the project and Rust compiles crates inside that project.
The commands that form the everyday loop
cargo new my-app cargo check cargo run cargo test
There are many more Cargo commands, but those four already explain the shape of the workflow. You create a project, repeatedly check it while editing, run it when you want to see behavior, and run tests when the project has them.
And what is Cargo.lock?
Cargo can create a lock file recording the exact dependency versions selected for the project. That makes a future build able to use the same resolved versions instead of silently choosing a different compatible set every time.
Beginners usually do not need to edit Cargo.lock by hand. Knowing why it exists is enough.