Future (Rust)
A future is an object that will, at some point in the future, return another object (the result of an async computation).
Ziggy's Cycles analogy
Ziggy’s is out of bikes. They take your money and give you a ticket (the future). Later you redeem the ticket (
await) for the actual bike.
reqwest::get(...) returns a future; .await extracts the result:
let body = reqwest::get("https://www.rust-lang.org")
.await?
.text()
.await?;Executors define what async/await actually does. Rust doesn’t bake in a specific runtime; you choose:
futures::executor::block_on: simplest, blocks the current thread until the future is ready- tokio: more sophisticated, can multiplex multiple active awaits onto different threads. Opt in with
#[tokio::main] async fn main() async_std: alternative runtime