Objlab
← News
Linguaggi e compilatori

Introduzione – Rust per i programmatori Python

Sintesi redazionale: URL dell'articolo: https://microsoft.github.io/RustTraining/python-book/ URL dei commenti: https://news.ycombinator.com/item?id=48423615 Punti: 4 # Commenti: 0. Fonte originale: https://microsoft.github.io/RustTraining/python-book/

<p># Rust for Python Programmers: Complete Training Guide</p><p>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.</p><p>## How to Use This Book</p><p>**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.</p><p>**Pacing recommendations:**</p><p>| Chapters | Topic | Suggested Time | Checkpoint |<br>|---|---|---|---|<br>| 1–4 | Setup, types, control flow | 1 day | You can write a CLI temperature converter in Rust |<br>| 5–6 | Data structures, enums, pattern matching | 1–2 days | You can define an enum with data and `match` exhaustively on it |<br>| 7 | Ownership and borrowing | 1–2 days | You can explain why `let s2 = s1` invalidates `s1` |<br>| 8–9 | Modules, error handling | 1 day | You can create a multi-file project that propagates errors with `?` |<br>| 10–12 | Traits, generics, closures, iterators | 1–2 days | You can translate a list comprehension to an iterator chain |<br>| 13 | Concurrency | 1 day | You can write a thread-safe counter with `Arc&lt;Mutex&lt;T&gt;&gt;` |<br>| 14 | Unsafe, PyO3, testing | 1 day | You can call a Rust function from Python via PyO3 |<br>| 15–16 | Migration, best practices | At your own pace | Reference material — consult as you write real code |<br>| 17 | Capstone project | 2–3 days | Build a complete CLI app tying everything together |</p><p>**How to use the exercises:**</p><p>- Chapters include hands-on exercises in collapsible<br>`&lt;details&gt;`</p><p>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<br>- The Rust Playground lets you run code without a local install</p><p>**Difficulty indicators:**</p><p>- 🟢<br>**Beginner**— Direct translation from Python concepts - 🟡<br>**Intermediate**— Requires understanding ownership or traits - 🔴<br>**Advanced**— Lifetimes, async internals, or unsafe code</p><p>**When you hit a wall:**</p><p>- Read the compiler error message carefully — Rust’s errors are exceptionally helpful<br>- Re-read the relevant section; concepts like ownership (ch7) often click on the second pass<br>- The Rust standard library docs are excellent — search for any type or method<br>- For deeper async patterns, see the companion Async Rust Training</p><p>## Table of Contents</p><p>### Part I — Foundations</p><p>#### 1. Introduction and Motivation 🟢</p><p>- The Case for Rust for Python Developers<br>- Common Python Pain Points That Rust Addresses<br>- When to Choose Rust Over Python</p><p>#### 2. Getting Started 🟢</p><p>#### 3. Built-in Types and Variables 🟢</p><p>#### 4. Control Flow 🟢</p><p>#### 5. Data Structures and Collections 🟢</p><p>#### 6. Enums and Pattern Matching 🟡</p><p>### Part II — Core Concepts</p><p>#### 7. Ownership and Borrowing 🟡</p><p>#### 8. Crates and Modules 🟢</p><p>#### 9. Error Handling 🟡</p><p>#### 10. Traits and Generics 🟡</p><p>#### 11. From and Into Traits 🟡</p><p>#### 12. Closures and Iterators 🟡</p><p>### Part III — Advanced Topics &amp; Migration</p><p>#### 13. Concurrency 🔴</p><p>#### 14. Unsafe Rust, FFI, and Testing 🔴</p><p>#### 15. Migration Patterns 🟡</p><p>#### 16. Best Practices 🟡</p><p>- Idiomatic Rust for Python Developers<br>- Common Pitfalls and Solutions<br>- Python→Rust Rosetta Stone<br>- Learning Path and Resources</p>