|
93 | 93 | 88| | }
|
94 | 94 | 89| 1|}
|
95 | 95 | 90| |
|
96 |
| - 91| 1|fn main() { |
97 |
| - 92| 1| let _ = g(10); |
98 |
| - 93| 1| let _ = h(9); |
99 |
| - 94| 1| let mut future = Box::pin(i(8)); |
100 |
| - 95| 1| j(7); |
101 |
| - 96| 1| l(6); |
102 |
| - 97| 1| executor::block_on(future.as_mut()); |
103 |
| - 98| 1|} |
104 |
| - 99| | |
105 |
| - 100| |mod executor { |
106 |
| - 101| | use core::{ |
107 |
| - 102| | future::Future, |
108 |
| - 103| | pin::Pin, |
109 |
| - 104| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, |
110 |
| - 105| | }; |
111 |
| - 106| | |
112 |
| - 107| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output { |
113 |
| - 108| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) }; |
114 |
| - 109| 1| |
115 |
| - 110| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new( |
116 |
| - 111| 1| |_| unimplemented!("clone"), |
117 |
| - 112| 1| |_| unimplemented!("wake"), |
118 |
| - 113| 1| |_| unimplemented!("wake_by_ref"), |
119 |
| - 114| 1| |_| (), |
120 |
| - 115| 1| ); |
121 |
| - 116| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; |
122 |
| - 117| 1| let mut context = Context::from_waker(&waker); |
123 |
| - 118| | |
124 |
| - 119| | loop { |
125 |
| - 120| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) { |
126 |
| - 121| 1| break val; |
127 |
| - 122| 0| } |
128 |
| - 123| | } |
129 |
| - 124| 1| } |
130 |
| - 125| |} |
| 96 | + 91| 1|async fn m(x: u8) -> u8 { x - 1 } |
| 97 | + ^0 |
| 98 | + 92| | |
| 99 | + 93| 1|fn main() { |
| 100 | + 94| 1| let _ = g(10); |
| 101 | + 95| 1| let _ = h(9); |
| 102 | + 96| 1| let mut future = Box::pin(i(8)); |
| 103 | + 97| 1| j(7); |
| 104 | + 98| 1| l(6); |
| 105 | + 99| 1| let _ = m(5); |
| 106 | + 100| 1| executor::block_on(future.as_mut()); |
| 107 | + 101| 1|} |
| 108 | + 102| | |
| 109 | + 103| |mod executor { |
| 110 | + 104| | use core::{ |
| 111 | + 105| | future::Future, |
| 112 | + 106| | pin::Pin, |
| 113 | + 107| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, |
| 114 | + 108| | }; |
| 115 | + 109| | |
| 116 | + 110| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output { |
| 117 | + 111| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) }; |
| 118 | + 112| 1| |
| 119 | + 113| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new( |
| 120 | + 114| 1| |_| unimplemented!("clone"), |
| 121 | + 115| 1| |_| unimplemented!("wake"), |
| 122 | + 116| 1| |_| unimplemented!("wake_by_ref"), |
| 123 | + 117| 1| |_| (), |
| 124 | + 118| 1| ); |
| 125 | + 119| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; |
| 126 | + 120| 1| let mut context = Context::from_waker(&waker); |
| 127 | + 121| | |
| 128 | + 122| | loop { |
| 129 | + 123| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) { |
| 130 | + 124| 1| break val; |
| 131 | + 125| 0| } |
| 132 | + 126| | } |
| 133 | + 127| 1| } |
| 134 | + 128| |} |
131 | 135 |
|
0 commit comments