RUSTPRINT

Search RustPrint by question, error, syntax, or task.

← Start with Rust

START 06 // THE PROJECT TOOL

What is Cargo?

If Rust is the language, Cargo is the tool that keeps an ordinary Rust project together. You will use it so often that understanding the job matters more than memorizing every command.

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 SITS BETWEEN YOU AND THE REPETITIVE WORK
YOUcargo run
→
CARGOreads the project and dependencies
→
RUSTC + PROGRAMbuild, then execute

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.

A MINIMAL CARGO.TOML
[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

Package

A Cargo-managed project described by a Cargo.toml manifest.

Crate

A Rust compilation unit. A package contains at least one crate and can contain binary and library crates.

Dependency

Another package your project uses instead of implementing that functionality itself.

crates.io

The Rust community package registry Cargo can use to obtain published dependencies.

DO NOT GET STUCK ON “PACKAGE VS CRATE” TODAY

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

CREATE → CHECK → RUN → TEST
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.

PRIMARY SOURCES

Official Cargo documentation