Improving our example 4 – pinning to the rescue
Fortunately, the changes we need to make are small, but before we continue and make the changes, let’s create a new folder and copy everything we had in our previous example over to that folder:
- Copy the entire
c-coroutines-problem
folder and name the new copye-coroutines-pin
- Open
Cargo.toml
and rename the name of the packagee-coroutines-pin
Tip
You’ll find the example code we’ll go through here in this book’s GitHub repository under the ch
09
/e-coroutines-pin
folder.
Now that we have a new folder set up, let’s start making the necessary changes. The logical place to start is our Future
definition in future.rs
.
future.rs
The first thing we’ll do is pull in Pin
from the standard library at the very top:
ch09/e-coroutines-pin/src/future.rs
use std::pin::Pin;
The only other change we need to make is in the definition of poll
in our Future
trait:
fn...