Improving our example 2-references 225 Let's take a look at what happens after the first wait point: ch09/b-coroutines-references/src/main. rs State0::Wait1(ref mut f1) => { match f1. poll(waker) { Poll State::Ready(txt) => { // Restore stack let writer = unsafe { &mut *self. stack. writer. take(). unwrap() }; //----Code you actually wrote---- writeln!(writer, «{txt}»). unwrap(); //--------------------------------- let fut2 = Box::new(http::Http::get("/400/ Hello Async Await")); self. state = State0::Wait2(fut2); // save stack self. stack. writer = Some(writer); } Poll State::Not Ready => break Poll State::Not Ready, } } The first change we make is regarding how we restore our stack. We need to restore our writer variable so that it holds a &mut String type that points to our buffer. To do this, we have to write some unsafe code that dereferences our pointer and lets us take a &mut reference to our buffer. Note Casting a reference to a pointer is safe. The unsafe part is dereferencing the pointer. Next, we add the line of code that writes the response. We can keep this the same as how we wrote it in our coroutine/wait function. Lastly, we save the stack state back since we need both variables to live across the wait point. Note We don't have to take ownership over the pointer stored in the writer field to use it since we can simply copy it, but to be somewhat consistent, we take ownership over it, just like we did in the first example. It also makes sense since if there is no need to store the pointer for the next await point, we can simply let it go out of scope by not storing it back.