The implementation of AsyncRead (tokio) on Boxed types has the following signature:
impl<T: ?Sized + AsyncRead + Unpin> AsyncRead for Box<T>
Why is Unpin required here by the trait bound? Why isn't the address stability ensured by Box enough?
Why is Unpin required here by the trait bound?
Plain old Box<T> is not pinned, so any async operations it generates will require that the underlying T does not care about pinning (i.e. is Unpin).
Why isn't the address stability ensured by Box enough?
You can move or replace the object in a plain Box, which would break the stability guarantee. Pin does not allow mut access without unsafe, preventing the value from escaping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With