Toolchain and language basics
Syllabus
Detailed content
Cargo and project structure
Cargo creates projects, resolves dependencies, builds binaries, runs tests, and produces lockfiles. Keep application code in src and reusable library interfaces in lib.rs. Use cargo check for fast feedback and cargo fmt and clippy to keep code consistent and catch common mistakes.
Variables, types, and control flow
Rust variables are immutable by default; mut marks a binding as changeable. Types are inferred where possible but can be written explicitly. Match handles patterns exhaustively, while if and loops express control flow. The compiler reports type and ownership errors early, so read diagnostics as a guide to clarify intended data flow.
Functions, strings, and collections
Functions declare input and return types. String owns UTF-8 data; &str borrows a string slice. Vec stores a growable sequence and HashMap stores key-value associations. Choose whether a function should own data or borrow it, and prefer slices when a function only needs to read a portion.