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 Apr 19, 2026

Chapters

About this tutorial

A practical tutorial to get you productive with Rust, the language for building reliable and efficient software.

Who This Is For

  • Developers with experience in other languages
  • Python developers wanting performance without sacrificing safety
  • Those wanting to learn systems programming with memory safety
  • Anyone interested in concurrent programming without data races
  • Developers building CLI tools, web services, or performance-critical applications

Contents

For Python Developers

  1. Python to Rust - Quick comparison guide for Python developers (start here!)

Fundamentals

  1. Introduction - What is Rust, 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 & 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 & Crates - Module system, packages, crates
  3. Concurrency - Threads, channels, Arc, Mutex

Ecosystem & Mastery

  1. Cargo & 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 all examples - Rust's compiler is your teacher
  3. Experiment - change the code and see what breaks
  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-3 weeks)

  1. Start with Chapter 0 - Python to Rust comparison
  2. Fundamentals (chapters 1-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) - Similar to protocols/interfaces
  6. Build a CLI tool or REST API

Systems Programmer (1-2 weeks)

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

Web Developer (1-2 weeks)

  1. Fundamentals (chapters 1-5)
  2. Error Handling (8)
  3. Traits (9)
  4. Modules & Crates (10)
  5. Learn async Rust (not in this tutorial)
  6. Build a REST API with actix-web or axum

General Purpose Programmer (2-3 weeks)

  1. Complete all chapters in order
  2. Focus on understanding 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: Fearless concurrency without data races
  • Tooling: Excellent package manager (Cargo), formatter, linter
  • Community: Helpful, welcoming, 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.