Tutorial

Rust Tutorial

A practical tutorial to get you productive with Rust for building reliable and efficient software. Covers ownership, traits, error handling, concurrency, and the Cargo ecosystem.

Tutorial·Difficulty: Intermediate·14 chapters·Updated May 10, 2026

Chapters

About this tutorial

A practical tutorial that gets you productive with Rust: the language for building reliable, efficient software.

Who This Is For

  • Developers with experience in another language
  • Python developers who want performance without losing safety
  • Anyone learning systems programming with memory safety
  • Developers writing concurrent code that should be free of data races
  • Builders of CLI tools, web services, and performance-critical applications

Contents

For Python Developers

  1. Python to Rust: Side-by-side comparison guide (start here)

Fundamentals

  1. Introduction: What Rust is, installation, first program
  2. Basics: Variables, types, operators, strings
  3. Ownership: Ownership, borrowing, references, lifetimes
  4. Control Flow: if, loops, pattern matching
  5. Functions: Functions, closures, methods

Core Concepts

  1. Structs and Enums: Structs, enums, pattern matching
  2. Collections: Vec, HashMap, String
  3. Error Handling: Result, Option, error propagation

Advanced Features

  1. Traits: Traits, generics, trait bounds
  2. Modules and Crates: Module system, packages, crates
  3. Concurrency: Threads, channels, Arc, Mutex

Ecosystem and Mastery

  1. Cargo and Ecosystem: Cargo, testing, documentation
  2. Best Practices: Idioms, patterns, common mistakes

How to Use This Tutorial

  1. Read sequentially for a complete learning path
  2. Type out the examples. The compiler is your teacher
  3. Experiment: change the code and see what the compiler says
  4. Build small projects after each section

Quick Reference

Essential Commands

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Create a new project
cargo new myproject
cd myproject

# Run a program
cargo run

# Build for release
cargo build --release

# Run tests
cargo test

# Check code without building
cargo check

# Format code
cargo fmt

# Run linter
cargo clippy

Hello World

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

Common Patterns

// Error handling with Result
fn read_file(path: &str) -> Result<String, std::io::Error> {
    std::fs::read_to_string(path)
}

// Option handling
let maybe_value: Option<i32> = Some(42);
if let Some(value) = maybe_value {
    println!("Got: {}", value);
}

// Pattern matching
match result {
    Ok(value) => println!("Success: {}", value),
    Err(e) => eprintln!("Error: {}", e),
}

// Iterators
let sum: i32 = vec![1, 2, 3, 4, 5]
    .iter()
    .map(|x| x * 2)
    .sum();

Learning Path Suggestions

Python Developer (2 to 3 weeks)

  1. Start with Chapter 0: Python to Rust comparison
  2. Fundamentals (chapters 1 to 5): focus on ownership differences
  3. Error Handling (8): replace exceptions with Result/Option
  4. Collections (7): HashMap, Vec vs dict, list
  5. Traits (9): close to protocols/interfaces
  6. Build a CLI tool or REST API

Systems Programmer (1 to 2 weeks)

  1. All fundamentals (chapters 1 to 5)
  2. Spend extra time on Ownership (3)
  3. Structs, Enums, Traits (6, 9)
  4. Concurrency (11)
  5. Build a CLI tool or file processor

Web Developer (1 to 2 weeks)

  1. Fundamentals (chapters 1 to 5)
  2. Error Handling (8)
  3. Traits (9)
  4. Modules and Crates (10)
  5. Learn async Rust (covered elsewhere)
  6. Build a REST API with actix-web or axum

General Purpose Programmer (2 to 3 weeks)

  1. Read every chapter in order
  2. Focus on the compiler messages
  3. Build progressively larger projects
  4. Read other people's Rust code

Why Rust?

  • Memory Safety: No null pointer dereferences, no data races
  • Performance: Zero-cost abstractions, comparable to C/C++
  • Concurrency: Compiler-checked thread safety, no data races
  • Tooling: Cargo, rustfmt, clippy, all in the box
  • Community: Welcoming, with thorough documentation

Additional Resources

Rust Version

This tutorial is written for Rust 2021 edition (Rust 1.56+) and updated for Rust 1.93. The examples work with both the 2021 and 2024 editions.