Medium
Polling an async block through Pin::new(&mut fut)
This hand-polls an async block once using a no-op waker (Waker::noop, stable since Rust 1.85). What happens when it is compiled?
main.rs
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll, Waker};
fn main() {
let mut fut = async {
let x = 5;
let r = &x;
std::future::ready(()).await;
*r
};
let mut cx = Context::from_waker(Waker::noop());
let pinned = Pin::new(&mut fut);
match pinned.poll(&mut cx) {
Poll::Ready(v) => println!("ready: {}", v),
Poll::Pending => println!("pending"),
}
}49 of 53 in Rust