I have been reading the rust async-book. But in the pinning section, Pinning - Asynchronous Programming in Rust, there is a paragraph that I have trouble understanding.
Some functions require the futures they work with to be
Unpin
. To use aFuture
orStream
that isn'tUnpin
with a function that requiresUnpin
types, you'll first have to pin the value using eitherBox::pin
(to create aPin<Box<T>>
) or thepin_utils::pin_mut!
macro (to create aPin<&mut T>
).Pin<Box<Fut>>
andPin<&mut Fut>
can both be used as futures, and both implementUnpin
.
- I was under the impression that all the Futures are !Unpin (not unpin). Is there any way to tell whether an async function or block creates a Future that is Unpin or not?
- If the Future is !Unpin, then the above paragraph says that pinned version of it (Pin<Box> or Pin<&mut dyn Future> ) is Unpin. But when I checked the Pin in std::pin - Rust, I saw that the pinned version is Unpin only if the original Future is also Unpin.
- Are the pinned versions of the Future also Futures? as said here:
Pin<Box<Fut>>
andPin<&mut Fut>
can both be used as futures,
Because I don't see anything related to that in the trait implementations for the Pin type.
Can someone please help me here? Thanks.