std-module

std::future: asynchronous computation interfaces

The module contains building blocks for computations that can advance in steps. It does not provide a general task scheduler or network runtime. A ready future is the simplest way to observe completion without a runtime. Expected stdout (not executed): Ready(12) Common mistake: Expecting importing std::future to start an event loop.

Formal Syntax & Structure

rust syntaxrust
use std::future::{Future, IntoFuture, ready, pending, poll_fn};

Working Example

Example Snippetrust
fn main() {    use std::{future::Future, task::{Context, Poll, Wake, Waker}, sync::Arc};    struct Noop;    impl Wake for Noop { fn wake(self: Arc<Self>) {} }    let w = Waker::from(Arc::new(Noop));    let mut cx = Context::from_waker(&w);    let mut f = std::pin::pin!(std::future::ready(12));    println!("{:?}", f.as_mut().poll(&mut cx));}
Rust Reference