Programming Foundations with Rust
Learn programming from scratch using Rust. Install the toolchain, write Cargo programs, use Vec and HashMap, handle errors with Result and Option, and read real Rust code. No prior programming experience required.
View badge details
About This Course
Learn programming from scratch using Rust as your first language. You start with variables, control flow, and functions; move into structs, enums, pattern matching, and error handling with Result and Option; and get your first look at Rust's ownership model. By the end you can read and write small Rust programs a converter, a guessing game, a word-frequency counter, a todo list and you've internalized value-vs-reference semantics in the context where they are natural rather than as a correction to habits built in another language.By the end of this course you will be able to install the Rust toolchain, write and run a small program with Cargo, use the standard-library collections (Vec, HashMap), handle fallible operations with Result and Option, define your own types with struct and enum, and read idiomatic beginner-level Rust code from the ecosystem.No prior programming experience required. Follows the current Rust 2024 edition on stable Rust 1.99.
Course Curriculum
21 Lessons
Rust in 2026 and the toolchain
Learn what Rust is, why it's trusted in production in 2026, and how its toolchain fits together. You'll explore where Rust sits in the language landscape (memory safety with C/C++ performance, no garbage collector), name real production systems that ship Rust today, understand what rustup, rustc, and cargo each do, and build and run your first Rust program with Cargo.
By the end of this lesson you will be able to describe Rust's value proposition in one sentence, identify the three core toolchain pieces, and create a working Rust project from scratch with cargo new and cargo run.
The first lesson of Course 1 (Programming Foundations with Rust) and the Programming with Rust skill path. Your Rust toolchain is already installed in this lab environment — Hollis Brennan, your recurring Rust mentor across all seven foundational courses, will walk you through what each piece does.
Your first cargo project - Lab Exercises
Hollis Brennan said in Lesson 1 that rustup, rustc, and cargo each have a specific role in getting your code from a text file into a running program. Now you drive them yourself. Across four short exercises you confirm the toolchain is live, generate your first project from scratch with cargo new, modify the generated source and manifest, rebuild, and finally produce an optimized release binary. No code to copy from a starter — the whole lab is you using the toolchain to make Rust happen.
Values, types, and variables
Learn how Rust represents data at the type-system level. You meet Rust's primitive numeric types (i32, u64, f64, bool, char, usize), see the two string types (String and &str) and when each is right, declare variables with let, let mut, and const, understand shadowing, and read type annotations and compiler-inferred types. By the end you can read any beginner-level Rust snippet and reason about what each binding holds and whether it can change.
Values, types, and variables — practice - Lab Exercises
Pure practice for the type system and binding mechanics covered in Lesson 2 (Values, types, and variables). Across five short exercises you declare integer, float, bool, char, String, and &str values, explore shadowing and mutable rebind, and watch the compiler catch an out-of-range literal and a type-changing rebind. The optional final exercise triggers integer overflow in debug mode and compares the behavior with a release build. By the end you can read and write every primitive declaration from Lesson 2 without hesitation.
Control flow — if, loop, while, for, match
Learn how Rust turns branching into typed values. You'll use if and else as expressions that bind directly to let, pick the right loop construct (loop, while, for) for each shape of iteration, and reach for match whenever a value falls into named cases — all the while leaning on the compiler to catch the two most common Beginner mistakes (silent-semicolon in an arm, non-exhaustive branch coverage).
By the end of this lesson you will be able to write Rust branching code that produces values rather than mutates them, choose a loop construct deliberately rather than by habit, and apply match on literal values, ranges, guards, and the _ catchall. Prepares you for Lesson 7 (pattern matching on enums and destructuring) and for every exercise from Lesson 5 (Fahrenheit converter) onward.
No prior programming experience required. Builds directly on Lesson 2 (values, types, variables).
Control flow practice — FizzBuzz and more - Lab Exercises
Practice the control-flow constructs from Lesson 3 by implementing the classic FizzBuzz program in two different styles — once with if/else if/else, once with a match on tuple patterns — then follow up with a short countdown loop and a sum-of-1-to-n accumulator. Pure syntax practice; no new concepts beyond what Lesson 3 taught. You'll leave the lab with four small functions you've built from scratch and a sharper feel for when to reach for if versus match versus loop versus for.
Functions and expression-oriented syntax
Learn how Rust functions are declared, how parameters and return types fit together, and how Rust's expression-oriented syntax lets a function body's last expression become its return value with no explicit return keyword. You will see the classic beginner trip where a stray semicolon converts a value into unit () and silently breaks a function, name the three common return shapes (single value, tuple, unit), and read your first recursive function.
By the end of this lesson you will be able to declare Rust functions with typed parameters, choose between implicit last-expression return and explicit early return, pick an appropriate return shape (single value, tuple, or unit) for a given situation, and trace a small recursive call stack. This lesson is the last of the pure-syntax foundations before Lesson 5's first hands-on lab.
Build a Fahrenheit/Celsius converter CLI - Lab Exercises
Write your first real Rust program — a small command-line converter that turns Fahrenheit into Celsius and back. Across the exercises you grow an empty main() into a working CLI: declare functions with typed signatures, use match on a direction argument, read values from std::env::args(), and handle parse errors with .expect(). By the end of the lab you can run cargo run -- f_to_c 72 and see a correctly converted value, exercising every concept covered in Lessons 1–4.
Collections — Vec and HashMap
The two Rust collections you will reach for every day: Vec for ordered sequences and HashMap for keyed lookups. You will learn when to pick each, the operations each supports, how to iterate them safely, and the idiomatic .entry().or_insert() pattern that cuts a two-step insert-or-update into one.
By the end of this lesson you will be able to pick Vec or HashMap for a given data shape, apply their common APIs (push/pop/len/iterate for Vec; insert/get/remove/iterate for HashMap), and use the entry API to update values in place.
Build a word-frequency counter - Lab Exercises
Build a small command-line program that answers the question "what are the most common words in this text?" Across six exercises you grow an empty main into a working CLI: read a text file from disk, tokenize the words, filter punctuation, count with a HashMap<String, u32>, sort by count, and print the top-N results. By the end of the lab you have a tool you can point at any text file and get a word-frequency report in milliseconds — the shape of problem Rust solves well, and the capstone that exercises every concept covered in Lessons 1–8.
Pattern matching — Option, match on enums, destructuring
Pattern matching is the backbone of safe Rust: it is how you work with values that might be absent, how you take apart compound data without reaching for null checks, and how you make the compiler verify you have covered every case. This lesson introduces Option, the match statement on enum variants, the one-arm shortcuts (if let and while let), and destructuring with guards. By the end you can write functions that never crash on a missing value and read match expressions in real Rust code.
By the end of this lesson you will be able to explain when Option is the right return type, use match to safely extract values from Some, choose between match / if let / while let for a given shape, and destructure tuples and structs in match arms with guards that filter on bound values.
Pattern matching practice — Option, if let, destructuring - Lab Exercises
Practice the pattern-matching toolkit from Lesson 7 by implementing four small functions that each exercise one piece: Option as a return type, while let draining a Vec, tuple destructuring with match guards, and iterator lookup with if let. By the end of the lab you can read and write idiomatic Rust pattern matches on Option, enums, and tuples without reaching for an unwrap you can't justify.
Error handling — panic, Result, Option, ?
Rust's error-handling story in one lesson: when to panic, when to return Result<T, E>, how ? compresses the plumbing, and where Option fits alongside Result. By the end you can read any Rust function signature that returns Result, follow the control flow of ?, and make a defensible call between .unwrap(), .expect(..), matching, and ? in your own code.
By the end of this lesson you will be able to decide when panic! is appropriate, choose between .unwrap() / .expect() / ? / match for a given failure case, and read Rust code that mixes Option and Result without second-guessing the control flow.
Hollis Brennan walks you through four topics: when panic is the right answer, Result as Option's sibling with context, the .unwrap() crutch versus the ? and match alternatives, and finally the desugaring of ? plus a one-paragraph intro to From conversions you'll meet again in Course 3.
Build a guess-the-number game - Lab Exercises
Build a classic console game from scratch. The program picks a secret number between 1 and 100 and the player guesses until correct — "too low", "too high", or "correct!" after each attempt — while a running counter tracks how many tries it took. Across the exercises you grow an empty main() into a working game: add the rand crate with cargo add (your first external dependency), pick a secret number, read guesses from stdin, parse strings into numbers with proper Result-based error handling, compare values with Ordering, loop until the player wins, and congratulate them with their try count. By the end you have a real tool you could ship to a friend, exercising everything from Lessons 1–8.
Structs, methods, derived traits
Build the first type you own. In this lesson you move from calling other people's data (Vec, HashMap, Option) into shaping your own: define a struct, give it methods via impl, derive the traits that let you print, clone, and compare it, and finish with the builder pattern that most crates reach for when a type needs many optional fields.
By the end you can declare a struct, write methods against it with the right receiver choice (&self, &mut self, or self), use #[derive(Debug, Clone, PartialEq)] to get three everyday capabilities for free, and recognize when a builder is worth the extra code vs when a plain struct literal is clearer.
Design a shopping cart with structs - Lab Exercises
You design a small shopping-cart library in Rust and watch the type system keep your invariants honest. You will declare two structs, write associated functions and methods, derive the traits that make debugging and copying simple, and finish with an exercise that demonstrates how self by value — different from &self and &mut self — hands ownership of the cart to a method that consumes it. By the end of this lab you can define your own types in Rust, add behaviour via impl, and read the compile errors that the three receiver forms produce when you reach for the wrong one.
Introducing ownership (gentle)
Rust's ownership model is the one feature with no close analog in Python, JavaScript, Java, or Go — so this gentle introduction walks through why it exists before showing how it works. You see the three alternatives (manual malloc/free, garbage collection, reference counting) side by side with Rust's compile-time ownership checker, then learn what happens when a value is "moved" from one variable to another and why Copy types behave differently. You finish by tying it back to the receiver types you already saw on struct methods in Lesson 11.
By the end of this lesson you will be able to explain, in your own words, why Rust uses compile-time ownership instead of a garbage collector; predict what the Rust compiler will say when a non-Copy value is reassigned; and pick the right receiver type (&self, &mut self, self) for a method based on what the method actually does. The full ownership story — lifetimes, borrow-checker deep dives, references in function signatures, slices — is reserved for Course 2.
Fix the borrow checker — 12 small drills - Lab Exercises
Twelve small broken Rust programs. Each one triggers exactly one borrow-checker or ownership error from Lesson 12 — move semantics, mutability, immutable-vs-mutable borrow conflicts, index moves, lifetime scope, and the &str↔String conversion. You read each compile error, locate the line, apply the smallest fix, and verify every drill prints "drill NN passed". By the end of the lab you can read any Beginner-level Rust compiler error and name the fix pattern it's pointing at — the single most useful skill you take out of Course 1.
Modules, crates, and reading real code
Finish the first teaching arc of Programming Foundations with Rust by learning how real projects are organized: modules and visibility (mod, pub, use), crates and the Cargo ecosystem (binary vs library, crates.io, semver), and a capstone walk-through of a real file from the ripgrep project where you tag every construct back to the lesson that taught it.
By the end of this lesson you will be able to explain how Rust finds module files on disk, differentiate binary crates from library crates and describe how Cargo versions dependencies via semver, and read a small Rust file from a shipping open-source project and identify which language features it uses.
Prepares you for Lesson 14 (the capstone todo-list build) and the full ownership deep-dive in Course 2.
Split a single-file program into modules - Lab Exercises
Take a working single-file Rust program and refactor it into a proper multi-file project: a library crate, a nested module split across files, one external dependency added via cargo add, and (optionally) a dedicated binary under src/bin/. You practice everything Lesson 13 covered — mod, pub, use, the crates.io ecosystem, and lib-vs-binary structure — on a greeting-generator CLI whose behavior stays identical while its shape changes under your hands. By the end you can take any single-file Rust program you encounter and know where every piece should live.
Build a tiny in-memory todo list - Lab Exercises
Capstone of Programming Foundations with Rust. You write a small interactive todo list REPL — add new items, list what you have, mark things done, remove things, and quit — all living in memory for a single session. By the end you have a working command-line tool that synthesizes every Rust concept from Lessons 1-13: structs with derived traits, Vec<Todo> state, mutable references, pattern matching on commands, parsing with Result, panic-free index validation, and a REPL control loop. This is the last lesson of Course 1; Course 2 (The Rust Ownership Model) goes deep on the model that makes all this safe at compile time.