The reason behind this choice is that there are basically two choices:
- Make the
AsyncWriteExt
methods take&mut W
and requireUnpin
. - Make the
AsyncWriteExt
methods takePin<&mut W>
and don't requireUnpin
.
With the first choice you can use the methods normally for types that are Unpin
, and for non-Unpin
types, you must tokio::pin!
it first. With the second choice, you must always tokio::pin!
it. Hence the first choice is more convenient.
You can't tokio::pin!
given only a &mut W
because you have no way of preventing the caller from moving the W
after the call. Pinning requires ownership.