Learn to read Rust using the Python you already know
- 1. Your first Rust project: cargo new next to uv init: the files you get, Cargo.toml next to pyproject.toml, and how to run it.
- 2. A tiny app: a function and a module: Write a function, move it into its own file with mod, pub and use, and run it.
- 3. Hello, variables and mut: fn main, println!, let, mut, shadowing, and why there are semicolons.
- 4. Numbers and strings: Fixed-size numbers, casts with as, and the two string types.
- 5. Functions and expressions: fn, types that are required, the last expression as the return value, and expressions everywhere.
- 6. if, loops and ranges: if needs a real bool, for i in 0..5 is range(5), while, and loop with a break value.
- 7. Vec and HashMap: A list is a Vec, a dict is a HashMap, plus slices, tuples, and why dict order is random.
- 8. Iterators and closures: List comprehensions become chains of .iter(), .filter(), .map() and .collect().
- 9. Structs and impl: A struct plus an impl block is a class: fields, a constructor and methods.
- 10. Enums and match: A type with a few named variants, some carrying data, and the match that must handle all of them.
- 11. Option instead of None: A value that might be missing, and the compiler making you handle the missing case.
- 12. Result and ? instead of exceptions: Errors in the return type: Ok, Err, match, the ? operator, unwrap and your own error enum.
- 13. Ownership and borrowing: Move, &, &mut and .clone(): the rules behind most Rust errors, explained with Python lists.
- 14. Traits instead of duck typing: trait, impl, default methods, generic bounds, Display and derive.
- 15. Reading compiler errors: How to read a rustc error from top to bottom and let its help: lines tell you the fix.
- 16. Building and running a real program: Command-line arguments, files, stdin, environment variables, errors with exit codes, and a Dockerfile.
- 17. Cargo in depth: dependencies and workspaces: A bigger project layout, the full Cargo.toml, Cargo.lock, adding dependencies, features, submodules and workspaces.
- 18. Tests, builds and shipping: #[test] and assert_eq!, reading cargo test output, debug vs release, one-file binaries, crates.io, and Rust inside Python wheels.
- 19. Reading real code: Modules, use, pub, attributes, generics and lifetimes, plus a realistic program to read line by line.
- 20. Memory without a garbage collector: How Python and Rust free memory: reference counting and gc vs owners and Drop, plus stack, heap and Box.
- 21. Shared ownership: Rc, RefCell and Weak: Many owners for one value, changing shared data, and why reference cycles leak in Rust but not in Python.
- 22. Threads without a GIL: thread::spawn, Arc and Mutex, channels and scoped threads, and why data races are compile errors.
- 23. The crates you'll meet everywhere: serde instead of json and pydantic, anyhow and thiserror for errors, and clap instead of argparse.
- 24. async/await vs asyncio: async fn and .await, tokio::join! and tokio::spawn, timeouts, and why async Rust needs a runtime like tokio.
- 25. Rust inside Python with PyO3: Write a Python module in Rust: functions, type conversions, exceptions, classes and the GIL.
- 26. Reading real projects: uv, ruff and pydantic-core: Five short pieces of real Rust from tools you use every day, read line by line next to the Python you would write.
Python → Rust phrasebook · Rust compiler error index