Improving our example 2 – references
Let’s set everything up for our next version of this example:
- Create a new folder called
b-coroutines-references
and copy everything froma-coroutines-variables
over to it - You can change the name of the project so that it corresponds with the folder by changing the
name
attribute in thepackage
section inCargo.toml
, but it’s not something you need to do for the example to work
Note
You can find this example in this book’s GitHub repository in the ch10/b-coroutines-references
folder.
This time, we’ll learn how to store references to variables in our coroutines by using the following coroutine/wait example program:
use std::fmt::Write; coroutine fn async_main() { let mut buffer = String::from("\nBUFFER:\n----\n"); let writer = &mut buffer; println!("Program starting"); ...