Site

Tools — Rust Development Toolchain

Tutorial 2.0  •  Rust / Learn

2.0 What This Teaches

This tutorial introduces the standard Rust toolchain. It covers:

2.1 rustup - Managing Rust Versions

rustup is the Rust toolchain installer. It downloads and manages versions of the Rust compiler (rustc), Cargo, and the standard library. Install it from rustup.rs; on Windows, run the downloaded rustup-init.exe. Common rustup commands:
rustup update              // update to latest stable
rustup show                // list installed toolchains
rustup target add wasm32-unknown-unknown  // add a cross-compile target
Rust releases a new stable version every six weeks. rustup update keeps you current without reinstalling anything.

2.2 cargo - Build and Package Manager

cargo is the tool you use for nearly everything: creating projects, compiling, running tests, adding dependencies, and publishing crates. You already used cargo new and cargo run in Tutorial 1. The commands you will use most often:
cargo new MyProject --bin   // create a binary crate
cargo new MyLib --lib       // create a library crate
cargo build                 // compile (debug)
cargo build --release       // compile (optimized)
cargo run                   // build and run
cargo test                  // build and run all tests
cargo check                 // type-check without producing a binary
cargo add serde             // add a dependency to Cargo.toml
cargo doc --open            // build and open HTML documentation
cargo check is faster than cargo build and is useful during active editing to catch type errors quickly without waiting for code generation.

2.3 rustfmt - Code Formatter

rustfmt reformats Rust source files to match the official Rust style guide. It is opinionated and non-negotiable about most rules, which eliminates style debates on teams.
cargo fmt              // format all files in the current crate
cargo fmt -- --check   // report differences without writing files
Most editors run rustfmt on save automatically when rust-analyzer is configured. The style it enforces is the same style used throughout the Rust standard library.

2.4 clippy - Linter

clippy is a collection of lints - analysis passes that detect common mistakes and non-idiomatic patterns. It goes beyond what the compiler flags and teaches Rust idioms as you work.
cargo clippy
Example: clippy warns when you write a loop that could be an iterator method, or when you clone a value that implements Copy. Each diagnostic names the lint and usually suggests an exact fix. Run clippy regularly. Warnings it emits are not errors, but ignoring them accumulates technical debt fast in Rust code.

2.5 rust-analyzer - IDE Support

rust-analyzer is the language server for Rust. It connects to any editor that supports the Language Server Protocol (LSP) - VS Code, Neovim, Emacs, and others. It provides: Install via your editor's extension marketplace. In VS Code, search for rust-analyzer in the Extensions panel. No further configuration is needed for standard Cargo projects.

2.6 Exercise

Exercise In your Hello project from Tutorial 1, run cargo clippy and cargo fmt -- --check. Then deliberately introduce a style inconsistency (extra spaces, wrong indentation) and run cargo fmt to see it corrected automatically.

2.7 Common Mistakes

Skipping cargo check during editing

Running cargo build for every edit is slow. Use cargo check in a terminal while editing - it catches type errors in a fraction of the time without producing an executable.

Ignoring clippy warnings

Clippy warnings are not noise. Each one points at a real issue or a non-idiomatic pattern. Suppressing them with #[allow(clippy::...)] is sometimes correct, but should be a deliberate decision, not a reflex.

Running rustup update infrequently

The Rust edition system means stable releases are always backwards-compatible, so updating is safe. Staying on an old stable means missing compiler improvements and library additions that the ecosystem increasingly depends on.

2.8 Key Terms

TermMeaning
rustup Toolchain installer and version manager for Rust
cargo Build system, package manager, and test runner for Rust
rustfmt Automatic code formatter enforcing the official Rust style
clippy Linter that detects common mistakes and non-idiomatic patterns
rust-analyzer Language server providing IDE features via the LSP protocol
LSP Language Server Protocol - standard interface between editors and language tools