Skip to content
BENIBIX Learn

Cargo

Development🛠️ Editors & ToolsPackages

Also known as Cargo Rust, Rust Package Manager, Cargo.toml, crates.io

The tool that fetches packages and builds code for the Rust language.

Think of it like

It is like a helper who gets the parts, builds the toy and wraps it.

Example

Jack starts a Rust project with cargo new. He adds one crate to Cargo.toml, and cargo run fetches it, builds and runs.

Why it matters

Every Rust project uses it the same way. You can open any one and build it with one command.

Definition

Cargo is the package manager and build tool for Rust. It downloads the packages your project needs, called crates. It then builds your code and can run it or test it. Your project's list of crates lives in a file called Cargo.toml. Cargo can also share your own crate on crates.io, the public shelf of Rust packages.

Example code

console
$ cargo new hello
$ cd hello
$ cargo run
Hello, world!
Cargo makes the project, builds it and runs it. The new project prints a greeting.
Cargo is the one for Rust. It fetches crates from crates.io.

Common mistake

Calling the Rust compiler by hand on a real project. Let Cargo do it, so the crates and settings come along.

Key takeaways

  1. 1
    Fetch. It downloads crates from crates.io.
  2. 2
    Build and run. One command builds, runs or tests.
  3. 3
    Cargo.toml. One file lists the whole project.

Learn it properly