Description
The current Payload
trait only requires that chunks be able to represent a slice of bytes. There may be cases where a user has several non-contiguous slices they would like to send. The Buf
trait makes it possible to represent those as a single chunk, without having to copy to a single contiguous array. Additionally, AsyncWrite::write_buf
can use that knowledge to call writev
.
Currently, in that situation, a user must either copy all the data into 1 buffer before sending to hyper, or send multiple chunks. hyper will by default not merge the chunks, and try to use writev
itself, so users can already benefit. However, that benefit may not be obvious. I'm wondering if allowing the chunk to be a Buf
itself would be more obvious.
Some potential downsides: it's a little more complicated to implement a custom Buf
than a AsRef<[u8]>
, though the common types already do. Additionally, it ties API compatibility to the Buf
trait, which is expect to have some breaking changes. However, hyper already publicly exposes a dependency on Bytes
from the same crate, and AsyncWrite
which also depends on Buf
, so probably not a big deal.
/cc @scottlamb