Photo - Michael H
Photo

Async

Rust Async can be a bit hard to understand at first!


Futures

The world at 88 mph

Rust Futures are broken down into two main traits:

  • core::future::Future: Representing the minimal required implementation for an asyncronous task. This is, notably, part of core and always available, even without alloc.
  • future::future::FutureExt: A large collection of functionality you might expect or want as a programmer.

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::
}

Streams

Go with the flow.

1867cdb4648edf7344e3233c665e62da7410a020