2 use std::marker::PhantomPinned;
12 fn new(delay: usize) -> Self {
17 impl Future for Delay {
19 fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
30 (&mut Delay::new(1)).await;
33 // Same thing implemented by hand
37 delay_ref: *mut Delay,
38 _marker: PhantomPinned,
46 delay_ref: ptr::null_mut(),
47 _marker: PhantomPinned,
52 impl Future for DoStuff {
54 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
56 let this = self.get_unchecked_mut();
60 this.delay_ref = &mut this.delay;
61 // Move to next state.
66 let delay = &mut *this.delay_ref;
67 Pin::new_unchecked(delay).poll(cx)
75 fn run_fut<T>(fut: impl Future<Output = T>) -> T {
79 impl Wake for MyWaker {
80 fn wake(self: Arc<Self>) {
85 let waker = Waker::from(Arc::new(MyWaker));
86 let mut context = Context::from_waker(&waker);
88 let mut pinned = pin!(fut);
90 match pinned.as_mut().poll(&mut context) {
91 Poll::Pending => continue,
92 Poll::Ready(v) => return v,
99 run_fut(DoStuff::new());