Step 6 of 6
Cargo: how real Rust projects are built
On this site you press Check and your code is compiled for you. On your own computer (and at work) you'll use Cargo, Rust's build tool and package manager. Install everything with rustup from rustup.rs: it installs rustc (the compiler), cargo, and the standard library, and keeps them up to date with rustup update.
A new project
$ cargo new hello
Creating binary (application) `hello` package
$ cd hello
$ cargo run
Compiling hello v0.1.0 (/home/you/hello)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.41s
Running `target/debug/hello`
Hello, world!
cargo new creates this:
hello/
├── Cargo.toml the project's settings: name, version, edition, dependencies
└── src/
└── main.rs your code, starting with fn main
It also starts a Git repository for the project, with a .gitignore file that keeps the build output out of it.
The commands you'll use every day
| Command | What it does |
|---|---|
cargo run |
build, then run the program |
cargo build |
build only (the program lands in target/debug/) |
cargo build --release |
build with optimizations, for speed (target/release/) |
cargo check |
check that the code compiles, without building a program: the fastest feedback |
cargo test |
run the project's tests |
cargo fmt |
format the code in the standard Rust style |
cargo clippy |
a linter that suggests more idiomatic, correct code |
cargo doc --open |
build documentation for your code and its dependencies |
Every Rust team uses cargo fmt and cargo clippy; many make them part of every pull request. The edition in Cargo.toml (this site uses 2024, the newest) picks which version of the language's rules a project uses; crates of different editions work together.
Your task
Print a small report about the cargo new project above. The program should print exactly these three lines (the third uses {} with the value 2024):
project: hello
main file: src/main.rs
edition: 2024