Setup & Toolchain
Goal: you can verify a working Rust toolchain and explain what each core cargo
command does — in under 30 minutes.
Install
Use rustup (the official toolchain manager). On Linux/macOS:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
Verify:
rustc --version # compiler — we standardize on 1.96.x
cargo --version # build tool + package manager
rustup update # run occasionally; Rust ships every 6 weeks
Why rustup, not apt? Distro packages are always stale. Rust’s release cadence is 6 weeks; rustup also manages multiple toolchains (stable / nightly / specific MSRV) and cross-compile targets. Everything CodeCora runs on ARM (aarch64) — rustup handles that transparently.
Editor
Any editor with rust-analyzer works. Minimum setup:
- rust-analyzer (LSP): completions, inline types, go-to-definition through macros
rustfmton save (the Format check in our CI iscargo fmt --all -- --check)- clippy as the lint source (CI runs
cargo clippy --all-targets -- -D warnings)
The cargo commands you will use daily
| Command | What it does | When |
|---|---|---|
cargo new <name> | scaffold a binary crate | starting any project |
cargo run | build + execute | inner loop |
cargo build --release | optimized build | perf / shipping |
cargo test | run all tests | before every commit |
cargo check | type-check without codegen | fastest feedback |
cargo clippy -- -D warnings | lint; warnings are errors | before every commit |
cargo fmt | auto-format (rustfmt) | before every commit |
cargo add <crate> | add a dependency | when a crate earns its place |
The house loop (burn this in — it is also our CI gate):
cargo fmt && cargo clippy --all-targets -- -D warnings && cargo test
Crates, packages, modules — 60 seconds
- Package = a
Cargo.toml(whatcargo newcreates). Builds one or more crates. - Crate = one compilation unit: a binary (
src/main.rs) or a library (src/lib.rs). - Module = a namespace inside a crate (
mod parser;→src/parser.rs). - Dependency = someone else’s crate, from crates.io,
pinned in
Cargo.toml+ locked inCargo.lock(commit the lockfile for binaries).
Lab: clone and run the gate lab
git clone https://github.com/codecoradev/rust-lms
cd rust-lms/labs/gate-hello
cargo test # expect: 2 passed
cargo run # Hello from Rust 0.1.0 — toolchain works!
cargo run -- --add 40 2 # 40 + 2 = 42
Exercises
- Verify — run the house loop above in
labs/gate-hello. All three must pass. - Break it — change
--addto printa - binstead. Re-run the loop. - Explain — out loud, in one sentence each: what
cargo checkdoes thatcargo buildskips, and why that makes it faster.
Done when: the house loop is green after your change, and you ran the binary at least once.