Rust for Python Programmers: Complete Training Guide
A comprehensive guide to learning Rust for developers with Python experience. This guide covers everything from basic syntax to advanced patterns, focusing on the conceptual shifts required when moving from a dynamically-typed, garbage-collected language to a statically-typed systems language with compile-time memory safety.
How to Use This Book
Self-study format: Work through Part I (ch 1β6) first β these map closely to Python concepts you already know. Part II (ch 7β12) introduces Rust-specific ideas like ownership and traits. Part III (ch 13β16) covers advanced topics and migration.
Pacing recommendations:
| Chapters | Topic | Suggested Time | Checkpoint |
|---|---|---|---|
| 1β4 | Setup, types, control flow | 1 day | You can write a CLI temperature converter in Rust |
| 5β6 | Data structures, enums, pattern matching | 1β2 days | You can define an enum with data and match exhaustively on it |
| 7 | Ownership and borrowing | 1β2 days | You can explain why let s2 = s1 invalidates s1 |
| 8β9 | Modules, error handling | 1 day | You can create a multi-file project that propagates errors with ? |
| 10β12 | Traits, generics, closures, iterators | 1β2 days | You can translate a list comprehension to an iterator chain |
| 13 | Concurrency | 1 day | You can write a thread-safe counter with Arc<Mutex<T>> |
| 14 | Unsafe, PyO3, testing | 1 day | You can call a Rust function from Python via PyO3 |
| 15β16 | Migration, best practices | At your own pace | Reference material β consult as you write real code |
| 17 | Capstone project | 2β3 days | Build a complete CLI app tying everything together |
How to use the exercises:
- Chapters include hands-on exercises in collapsible
<details>blocks with solutions - Always try the exercise before expanding the solution. Struggling with the borrow checker is part of learning β the compiler's error messages are your teacher
- If you're stuck for more than 15 minutes, expand the solution, study it, then close it and try again from scratch
- The Rust Playground lets you run code without a local install
Difficulty indicators:
- π’ Beginner β Direct translation from Python concepts
- π‘ Intermediate β Requires understanding ownership or traits
- π΄ Advanced β Lifetimes, async internals, or unsafe code
When you hit a wall:
- Read the compiler error message carefully β Rust's errors are exceptionally helpful
- Re-read the relevant section; concepts like ownership (ch7) often click on the second pass
- The Rust standard library docs are excellent β search for any type or method
- For deeper async patterns, see the companion Async Rust Training
Table of Contents
Part I β Foundations
1. Introduction and Motivation π’
- The Case for Rust for Python Developers
- Common Python Pain Points That Rust Addresses
- When to Choose Rust Over Python
2. Getting Started π’
3. Built-in Types and Variables π’
4. Control Flow π’
5. Data Structures and Collections π’
6. Enums and Pattern Matching π‘
Part II β Core Concepts
7. Ownership and Borrowing π‘
8. Crates and Modules π’
9. Error Handling π‘
10. Traits and Generics π‘
11. From and Into Traits π‘
12. Closures and Iterators π‘
Part III β Advanced Topics & Migration
13. Concurrency π΄
14. Unsafe Rust, FFI, and Testing π΄
15. Migration Patterns π‘
16. Best Practices π‘
- Idiomatic Rust for Python Developers
- Common Pitfalls and Solutions
- PythonβRust Rosetta Stone
- Learning Path and Resources