4 use std::marker::PhantomPinned;
14 fn new(delay: usize) -> Self {
19 impl Future for Delay {
21 fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
32 (&mut Delay::new(1)).await;
35 // Same thing implemented by hand
39 delay_ref: *mut Delay,
40 _marker: PhantomPinned,
48 delay_ref: ptr::null_mut(),
49 _marker: PhantomPinned,
54 impl Future for DoStuff {
56 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
58 let this = self.get_unchecked_mut();
62 this.delay_ref = &mut this.delay;
63 // Move to next state.
68 let delay = &mut *this.delay_ref;
69 Pin::new_unchecked(delay).poll(cx)
77 fn run_fut<T>(fut: impl Future<Output = T>) -> T {
81 impl Wake for MyWaker {
82 fn wake(self: Arc<Self>) {
87 let waker = Waker::from(Arc::new(MyWaker));
88 let mut context = Context::from_waker(&waker);
90 let mut pinned = pin!(fut);
92 match pinned.as_mut().poll(&mut context) {
93 Poll::Pending => continue,
94 Poll::Ready(v) => return v,
101 run_fut(DoStuff::new());