Skip to content
iamnoobs

Beginner to advanced · 13 modules · 39 lessons

Learn Rust: Beginner to Advanced

Learn Rust from first principles through ownership, borrowing, data modeling, traits, error handling, Cargo, smart pointers, concurrency, files, and application design with guided lessons, code examples, quizzes, checkpoints, and a capstone.

Who this is for: Beginners and developers who want to learn Rust for dependable command-line tools, systems programming, performance-sensitive applications, and concurrent services.

Prerequisites: No prior Rust experience is required. Familiarity with files and running terminal commands is helpful. Examples target stable Rust and use the standard library unless otherwise noted; some examples are snippets rather than complete standalone programs and are explanatory rather than executed on this website.

Meet Rust and its toolchain

Your first Rust program

A Rust executable begins in the main function.

A standalone Rust executable commonly defines fn main(). println! is a macro that prints formatted text followed by a newline. Macros are invoked with an exclamation mark and can accept syntax that ordinary function calls cannot.

Rust is compiled, and the compiler checks types and many safety rules before producing an executable. Start with a small program, compile it, and read the first meaningful compiler diagnostic if it fails.

Guided example

Read through this example; code examples are for learning and are not executed on this site.

fn main() {
    println!("Hello, Rust!");
}

Relevance quest · +10 XP

Which function is the usual entry point of a Rust executable?

Choose your answer

Mark this lesson complete when you are ready.

Module checkpoint: Meet Rust and its toolchain

Create a Cargo project, print three lines, run cargo fmt and cargo check, then fix one deliberate syntax error by following the compiler diagnostic.

After this module, you can:

  • Describe how rustc and Cargo fit into the development workflow.
  • Recognize fn main and basic Rust syntax.
  • Use rustfmt and compiler diagnostics to improve code.

Full curriculum

What you will learn

1. Meet Rust and its toolchain

Beginner

Understand Rust's goals, compile a small program, and use Cargo and compiler messages confidently.

  1. Your first Rust program

    A Rust executable begins in the main function.

  2. Create a project with Cargo

    Cargo manages Rust projects, builds, dependencies, and tests.

  3. Formatting and compiler feedback

    Use standard formatting and treat errors as guidance about program structure.

Module checkpoint: Create a Cargo project, print three lines, run cargo fmt and cargo check, then fix one deliberate syntax error by following the compiler diagnostic.

2. Variables, types, and constants

Beginner

Learn mutability, scalar and compound types, type inference, and explicit conversions.

  1. Bindings and mutability

    Rust bindings are immutable by default unless declared with mut.

  2. Scalar types and inference

    Integers, floating-point values, Booleans, and characters represent common scalar data.

  3. Constants, tuples, arrays, and shadowing

    Constants, tuples, arrays, and shadowing provide different ways to express stable or grouped data.

Module checkpoint: Write a small program containing a constant, a mutable counter, a tuple, and an array. Print selected values and explain why each type fits its role.

3. Expressions, decisions, and loops

Beginner

Use Rust expressions, branching, pattern matching, and loops to model program flow.

  1. Conditions and if expressions

    In Rust, if is an expression and branches that return a value must have compatible types.

  2. Match and pattern matching

    match checks a value against patterns and requires exhaustive handling.

  3. Loop, while, for, and ranges

    Rust offers loop, while, and for for different repetition patterns.

Module checkpoint: Write a temperature classifier with if, a status classifier with match, and a loop that prints the values 1 through 5. Explain the endpoint of each range.

4. Functions, closures, and control-flow results

Beginner

Write reusable functions, understand return values, and learn the foundations of closures and early exits.

  1. Functions and parameters

    A function signature describes its inputs and output type.

  2. Return values, tuples, and early return

    Functions can return tuples and use return for an explicit early exit.

  3. Closures and captured values

    Closures are anonymous functions that can capture values from their surrounding scope.

Module checkpoint: Create a function that returns a useful result, one that reports absence with Option, and a closure used to transform a list of numbers.

5. Ownership, borrowing, and slices

Intermediate

Understand Rust's ownership model, borrow references safely, and work with slices without unnecessary copying.

  1. Ownership and moves

    Each owned value has an owner, and ownership moves can transfer responsibility without copying the data.

  2. References and borrowing

    References let functions access a value without taking ownership of it.

  3. Slices and borrowing rules

    Slices borrow a contiguous part of a collection without owning it.

Module checkpoint: Write a function that accepts a string slice and returns its length, then write a function that borrows an integer slice and computes its sum. Identify who owns each input.

6. Structs, enums, and pattern matching

Intermediate

Model domain data with structs and enums, then use pattern matching to handle variants explicitly.

  1. Structs and methods

    Structs group named fields into a type that represents one concept.

  2. Enums and Option

    Enums represent a value that can be one of several named variants.

  3. Match, if let, and destructuring

    Patterns extract data from enum variants, tuples, and structs.

Module checkpoint: Model a task with a struct and an enum status. Write a method to update it and handle an Option value using match or if let.

7. Collections, strings, and iterators

Intermediate

Store dynamic collections, work safely with UTF-8 strings, and transform data with iterators.

  1. Vectors and dynamic sequences

    Vec<T> stores a growable sequence of values of one type.

  2. String, &str, and HashMap

    String owns growable UTF-8 text, &str borrows text, and HashMap stores key-value pairs.

  3. Iterators and transformations

    Iterators express sequences of values and can be composed into clear data transformations.

Module checkpoint: Build a small collection of scores, calculate the average using iteration, store per-student totals in a HashMap, and handle missing keys without assuming they exist.

8. Option, Result, and error handling

Intermediate

Make absence and failures explicit, propagate errors with ?, and choose between recoverable errors and panics.

  1. Handling optional values

    Option represents a value that may or may not be present.

  2. Result and the question-mark operator

    Result<T, E> represents success or failure, and ? propagates compatible errors.

  3. Panics, validation, and error context

    Use Result for expected failures and reserve panics for broken assumptions or unrecoverable situations.

Module checkpoint: Write a function that parses an integer from text and returns Result. Handle a missing collection element with Option, and describe which errors should be shown to a user rather than panic.

9. Generics, traits, and lifetimes

Advanced

Reuse behavior with generics and traits, understand trait bounds, and read lifetime annotations in borrowed data APIs.

  1. Generic functions and types

    Generics let code work with multiple types while retaining compile-time type checking.

  2. Traits and trait bounds

    Traits describe behavior that types can implement, while bounds specify the behavior a generic type must provide.

  3. Reading lifetime annotations

    Lifetime annotations describe relationships between references rather than extending data's lifetime.

Module checkpoint: Implement a generic function with a trait bound, define a small trait for a domain type, and read a borrowed return type with an explicit lifetime. Explain what each bound guarantees.

10. Modules, Cargo, and testing

Intermediate

Organize code into modules and crates, manage dependencies, and create reliable automated tests.

  1. Modules, paths, and visibility

    Modules organize code and Rust privacy controls which items can be accessed from outside a module.

  2. Cargo dependencies and reproducible builds

    Cargo resolves dependencies and records project configuration and versions.

  3. Unit tests and integration tests

    Rust supports unit tests in source modules and integration tests under the tests directory.

Module checkpoint: Split a small application into two modules, make only the necessary items public, add unit tests for normal and boundary cases, and run cargo fmt, cargo test, and cargo clippy.

11. Smart pointers and interior mutability

Advanced

Learn when ownership wrappers such as Box, Rc, Arc, Cell, and RefCell are useful, and understand their tradeoffs.

  1. Box and heap allocation

    Box<T> owns a value allocated on the heap and gives it a stable indirection in the type structure.

  2. Shared ownership with Rc and Arc

    Rc and Arc allow multiple owners to share a value, with different concurrency guarantees.

  3. Cell, RefCell, and Mutex

    Interior mutability permits mutation through a shared outer reference using specific runtime or synchronization rules.

Module checkpoint: Model a recursive data structure with Box and compare it with a shared-ownership example. Explain why Rc, Arc, RefCell, and Mutex solve different problems.

12. Threads, channels, and asynchronous concepts

Advanced

Coordinate concurrent work using threads, message passing, and shared state, while understanding where async runtimes fit.

  1. Threads and join handles

    Rust threads can execute work concurrently while ownership rules constrain what data crosses thread boundaries.

  2. Channels and synchronized state

    Channels send values between concurrent tasks, while mutexes protect shared mutable state.

  3. Async functions and futures

    async functions describe work that can be polled to completion by an executor.

Module checkpoint: Create two worker threads and coordinate their results. Then compare message passing with a shared Mutex-protected counter, documenting how errors and shutdown are handled.

13. Files, command-line apps, performance, and unsafe boundaries

Advanced

Build practical Rust command-line programs, process files safely, measure performance, and understand the limits of unsafe code.

  1. Reading and writing files

    File operations return Results because permissions, paths, and storage can cause failures.

  2. Command-line arguments and application layers

    A reliable CLI separates argument parsing, domain operations, and presentation.

  3. Performance, profiling, and unsafe code

    Measure performance before optimizing, and treat unsafe blocks as explicit proof obligations.

Module checkpoint: Build a CLI tool that reads a text file, validates a command, summarizes the content, and writes a report. Test I/O errors and invalid arguments, then profile only if you have evidence of a performance problem.

Put it together

Rust capstone: Personal Study Tracker

Build a command-line study tracker that adds, lists, updates, completes, filters, and removes study sessions. Model records with structs and enums, use Vec and HashMap where appropriate, validate input, return Result for recoverable failures, and persist records to a JSON file. Add tests and consider a threaded or HTTP extension after the core application is reliable.

  1. 1Create a Cargo project and define a StudySession type with an ID, topic, minutes, completion status, and suitable date or category fields.
  2. 2Implement focused functions for adding, listing, updating, filtering, and deleting sessions; pass borrowed data when ownership does not need to change.
  3. 3Validate command-line input and return clear errors for invalid minutes, missing IDs, malformed data, and unavailable files.
  4. 4Persist records to JSON using an appropriate serialization approach, document any external dependency, and handle read/write failures deliberately.
  5. 5Add unit tests for ordinary, empty, duplicate, invalid, and boundary cases; run cargo fmt, cargo test, and cargo clippy.
  6. 6Optionally add worker-thread processing or an HTTP API, explain ownership and synchronization decisions, and document build and run instructions.

Progress is saved in this browser when local storage is available. You can continue without an account; changing browsers or clearing browser data may remove saved progress. Examples are not executed by the site.