Photo - Jason Leung
Photo

Futures

Rust Futures are broken down into two main traits:

You'll also find a bunch of handy functions just vibing in futures::future.

Let's take a look!

What is a Future anyways?

Creating Futures from thin air

The laziest possible future we can make, is a futures::future::lazy. It's right there in the name.

It takes a closure and runs it later poll it.

use core::future::Future;
use futures::executor::block_on;

#[tokio::main]
async fn main() {
    let input = futures::lazy(|_| 1);
    let output = block_on(input)
    tracing::
}

            231666f96329f6c37d7736c5c0be5d5634043289