How pyo3-async-runtimes facilitates async interoperability
mainThe library acts as a bridge between Rust's async model (Futures) and Python's async model (Coroutines/Asyncio).
- Rust $\rightarrow$ Python: When you want to call a Python
async deffunction from Rust, you useinto_futureto turn the returned Python coroutine into a RustFuture. This allows you to use.awaitin your Rust code. - Python $\rightarrow$ Rust: When you want to expose a Rust
async fnto Python, you usefuture_into_pyto wrap the RustFutureinto a Python object. This allows Python users to use theawaitkeyword on your Rust-provided functions.
All async Python code runs on the default asyncio event loop, and pyo3-async-runtimes manages the lifecycle of the corresponding event loops and integrates with popular Rust runtimes like tokio and async-std.