1 use std::future::Future;
2 use std::pin::Pin;
3 use std::ptr;
4 use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
5
6 // Executor for a future that resolves immediately (test only).
7 #[allow(clippy::missing_panics_doc)]
block_on_simple<F: Future>(mut fut: F) -> F::Output8 pub fn block_on_simple<F: Future>(mut fut: F) -> F::Output {
9 unsafe fn clone(_null: *const ()) -> RawWaker {
10 unimplemented!()
11 }
12
13 unsafe fn wake(_null: *const ()) {
14 unimplemented!()
15 }
16
17 unsafe fn wake_by_ref(_null: *const ()) {
18 unimplemented!()
19 }
20
21 unsafe fn drop(_null: *const ()) {}
22
23 let data = ptr::null();
24 let vtable = &RawWakerVTable::new(clone, wake, wake_by_ref, drop);
25 let raw_waker = RawWaker::new(data, vtable);
26 let waker = unsafe { Waker::from_raw(raw_waker) };
27 let mut cx = Context::from_waker(&waker);
28
29 // fut does not move until it gets dropped.
30 let fut = unsafe { Pin::new_unchecked(&mut fut) };
31
32 match fut.poll(&mut cx) {
33 Poll::Ready(output) => output,
34 Poll::Pending => panic!("future did not resolve immediately"),
35 }
36 }
37