Installing Rust and Cargo
Before the library program can run anywhere, you need the compiler and the tool that drives it. Rust ships them as one bundle with a single installer, and after that one command creates a whole project for you.
The rule
rustup installs Rust; Cargo builds, runs and checks your project.
rustup is the official installer and version manager. It puts three things on your machine: rustc (the compiler), cargo (the build tool and package manager) and the standard library. Later, rustup update moves you to the newest release. Confirm the install with:
rustc --version
cargo --versionCargo is how you actually work day to day. You rarely call rustc yourself.
cargo new shelf # make a new project called shelf
cd shelf
cargo run # compile, then runcargo new creates this layout:
shelf/
├── Cargo.toml # the package: name, version, edition, dependencies
└── src/
└── main.rs # fn main() lives hereCargo.toml is written in TOML:
[package]
name = "shelf"
version = "0.1.0"
edition = "2021"
[dependencies]The everyday commands:
cargo check: run the compiler's checks, skip making the executable. Fastest feedback.cargo build: compile intotarget/debug/.cargo run: build if needed, then run.cargo build --release: an optimised build intarget/release/, slower to compile, faster to run.
The shortcut
Think of the commands as a ladder, each step doing a little more: check → build → run → release. Climb only as high as you need.
Editing
You change a function and want to know if it compiles.
cargo checkanswers in a moment.
The trap is timing speed with a debug build. Debug builds skip most optimisation, so they can be many times slower than --release.
Drills
Answer fast — trust the rule.
Which tool installs Rust and later updates it to a new version?
Which command gives the fastest "does it compile?" answer while editing?
Where does the package's name, version and dependency list live?
Your program seems slow. What should you do before measuring it?
Remember
- rustup installs and updates
rustc,cargoand the standard library. - Ladder:
cargo check→cargo build→cargo run→cargo build --release. - Trap: measuring speed on a debug build.
