Pin is a whole deal on its own - if you want to get into the intricacies of using it, we can, but I think the simplest option is to just use
Box::pin to turn
Pin<Box<T>>. Something in a
Pin is guaranteed to never move, and using a box here gives that guarantee.
Pin::as_mut can grab a
Pin<&mut T> from
If you want to dive deeper into this, the
std::pin module docs have a lot of detail about pinning itself, and chapter 4.1 of the rust book describes how this interacts with futures and why we need it. This reddit post is also pretty nice advice on concretely using it.
If you want to just use futures, though, I'd recommend reading through the async book and using an existing executor, like
async-std. Or if you want a super simple executor, something like
It's expected that all most Future users use an existing executor, and that the only pieces of code calling
Future::poll are executor implementations.