async/await 155 So, let's take this a step further. To avoid confusion, and since our coroutines only yield to the calling function right now (there is no scheduler, event loop, or anything like that yet), we use a slightly different syntax called coroutine/wait and create a way to have these state machines generated for us. coroutine/wait The coroutine/wait syntax will have clear similarities to the async/await syntax, although it's a lot more limited. The basic rules are as follows: Every function prefixed with coroutine will be rewritten to a state machine like the one we wrote. The return type of functions marked with coroutine will be rewritten so they return-> impl Future<Output = String> (yes, our syntax will only deal with futures that output a String ). Only objects implementing the Future trait can be postfixed with. wait. These points will be represented as separate stages in our state machine. Functions prefixed with coroutine can call normal functions, but normal functions can't call coroutine functions and expect anything to happen unless they call poll on them repeatedly until they return Poll State::Ready. Our implementation will make sure that if we write the following code, it will compile to the same state machine we wrote at the start of this chapter(with the exception that all coroutines will return a String): coroutine fn async_main() { println!("Program starting") let txt = Http::get("/1000/Hello World"). wait; println!("{txt}"); let txt2 = Http::("500/Hello World2"). wait; println!("{txt2}"); } But wait. coroutine/wait aren't valid keywords in Rust. I would get a compilation error if I wrote that! Y ou're right. So, I created a small program called corofy that rewrites the coroutine/wait functions into these state machines for us. Let's explain that quickly. corofy—the coroutine preprocessor The best way of rewriting code in Rust is using the macro system. The downside is that it's not clear exactly what it compiles down to, and expanding the macros is not optimal for our use case since one 