Sections
IntroductionGetting StartedWhat is Rust?InstallationYour First ProjectIDE SetupRust Language FundamentalsVariables and TypesFunctions and Control FlowOwnershipBorrowing and SlicesStructs and EnumsError HandlingCollectionsClosures and IteratorsTraits and GenericsModules and CratesProject Setup and ToolingCargo In DepthDependenciesTestingDaily WorkflowPyO3 and LogferryPyO3 OverviewExposing FunctionsExposing ClassesError Handling in PyO3Multithreading and the GILlogferry WalkthroughDistributionCargo CheatsheetReferencePython → Rust CheatsheetTroubleshooting
PyO3 and Logferry
1 min read
This chapter covers the PyO3 bridge between Rust and Python, using logferry as the concrete working example throughout.
Articles
| Article | Topics covered |
|---|---|
| PyO3 Overview | What PyO3 is, project setup, type mapping table |
| Exposing Functions | #[pyfunction], signatures, default arguments |
| Exposing Classes | #[pyclass], #[pymethods], getters, __repr__ |
| Error Handling in PyO3 | PyResult, From<MyError>, Python exception types |
| Multithreading and the GIL | py.allow_threads, thread::scope, Send + Sync |
| logferry Walkthrough | End-to-end walk through src/lib.rs |
| Distribution | maturin build, wheels, type stubs, mixed layouts |
Prerequisites
Chapter 2 — Rust Language Fundamentals, especially Error Handling and Traits and Generics.
Next
Chapter 5 — Reference for quick-lookup tables and troubleshooting.