Coroutines and async/await 154 Our state machine will be efficient, but that's pretty much it. However, you might also notice that there is a system to the craziness. This might not come as a surprise, but the code we wrote could be much simpler if we tagged the start of each function and each point we wanted to yield control back to the caller with a few keywords and had our state machine generated for us. And that's the basic idea behind async/await. Let's go and see how this would work in our example. async/await The previous example could simply be written as the following using async/await keywords: async fn async_main() { println!("Program starting") let txt = Http::get("/1000/Hello World"). await; println!("{txt}"); let txt2 = Http::("500/Hello World2"). await; println!("{txt2}"); } That's seven lines of code, and it looks very familiar to code you' d write in a normal subroutine/function. It turns out that we can let the compiler write these state machines for us instead of writing them ourselves. Not only that, we could get very far just using simple macros to help us, which is exactly how the current async/await syntax was prototyped before it became a part of the language. Y ou can see an example of that at https://github. com/alexcrichton/futures-await. The downside is of course that these functions look like normal subroutines but are in fact very different in nature. With a strongly typed language such as Rust, which borrow semantics instead of using a garbage collector, it's impossible to hide the fact that these functions are different. This can cause a bit of confusion for programmers, who expect everything to behave the same way. Coroutine bonus example To show how close our example is to the behavior we get using the std::future:::Future trait and async/await in Rust, I created the exact same example as we just did in a-coroutines using “proper” futures and the async/await syntax instead. The first thing you'll notice is that it only required very minor changes to the code. Secondly, you can see for yourself that the output shows the exact same program flow as it did in the example where we hand-wrote the state machine ourselves. Y ou will find this example in the ch07/a-coroutines-bonus folder in the repository.