1 use std::future::Future; use std::sync::Arc; use std::task::{Context, Poll, Wake}; use std::thread::{self, Thread}; 2 /// A waker that wakes up the current thread when called. 3 struct ThreadWaker(Thread); wake(self: Arc<Self>)4impl Wake for ThreadWaker {fn wake(self: Arc<Self>) {self.0.unpark();}} 5 /// Run a future to completion on the current thread. block_on<T>(fut: impl Future<Output = T>) -> T6fn block_on<T>(fut: impl Future<Output = T>) -> T { 7 // Pin the future so it can be polled. 8 let mut fut = Box::pin(fut); 9 // Create a new context to be passed to the future. 10 let t = thread::current();let waker = Arc::new(ThreadWaker(t)).into(); 11 let mut cx = Context::from_waker(&waker); 12 // Run the future to completion. 13 loop {match fut.as_mut().poll(&mut cx) { 14 Poll::Ready(res) => return res, Poll::Pending => thread::park(), 15 } 16 } 17 } edition() -> i3218async fn edition() -> i32 {2018} main()19pub fn main(){println!("{}", block_on(edition()));} 20