Improving our example 1-variables 219 Note Futures created by async/await in Rust store this data in a slightly more efficient manner. In our example, we store every variable in a separate struct since I think it's easier to reason about, but it also means that the more variables we need to store, the more space our coroutine will need. It will grow linearly with the number of different variables that need to be stored/restored between state changes. This could be a lot of data. For example, if we have 100 state changes that each need one distinct i64-sized variable to be stored to the next state, that would require a struct that takes up 100 * 8b = 800 bytes in memory. Rust optimizes this by implementing coroutines as enums, where each state only holds the data it needs to restore in the next state. This way, the size of a coroutine is not dependent on the total number of variables ; it's only dependent on the size of the largest state that needs to be saved/restored. In the preceding example, the size would be reduced to 8 bytes since the largest space any single state change needed is enough to hold one i64-sized variable. The same space will be reused over and over. The fact that this design allows for this optimization is significant and it's an advantage that stackless coroutines have over stackful coroutines when it comes to memory efficiency. The next thing we need to change is the new method on Coroutine0 : ch09/a-coroutines-variables/src/main. rs impl Coroutine0 { fn new()-> Self { Self { state: State0::Start, stack: Stack0::default(), } } } The default value for stack is not relevant to us since we'll overwrite it anyway. The next few steps are the ones of most interest to us. In the Future implementation for Coroutine0, we'll pretend that corofy added the following code to initialize, store, and restore the stack variables for us. Let's take a look at what happens on the first call to poll now: ch09/a-coroutines-variables/src/main. rs State0::Start => { // initialize stack (hoist variables) self. stack. counter = Some(0); //----Code you actually wrote---- println!("Program starting");