-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should Payload data be Buf
instead of AsRef<[u8]>
?
#1508
Comments
cc @carllerche |
The Roughly speaking, structs should usually be generic over "Leaf" APIs should take If one needs to iterate a buffer multiple types, then taking I hope this helps. |
Also cc @sfackler, I believe I've noticed you have a custom body implementation. Some additional pros of requiring |
I already use |
Thanks for ccing me, and sorry I'm a little late to the party. I'm a little confused about the desired benefits. From the first comment, it sounds to me like you're confident that the pre-existing
fwiw, I mentioned on reddit the idea of a different chunk bound than
|
So, sort of. Say you have 2 large chunks available immediately. You can make them available in But, maybe you have a whole bunch of slices ready immediately. You could push them all individually onto
hyper doesn't actually dereference the slice, it passes it directly to
I think this would something about |
Interesting, thanks. It's not clear to me at first glance that a
Sorry, I was oversimplifying by partitioning the world into "my application" vs "hyper" without thinking about the details of how hyper interacts with tokio and such. But hyper is the thing my application is sending the chunks to. If I want to provide an
There definitely exist applications that do both those things. For example, my moonfire-nvr composes arbitrary-length
Interesting. I'll have to study how that works. Maybe it's also the answer for my question above about |
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. TheBuf
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 callwritev
.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 aBuf
itself would be more obvious.Some potential downsides: it's a little more complicated to implement a custom
Buf
than aAsRef<[u8]>
, though the common types already do. Additionally, it ties API compatibility to theBuf
trait, which is expect to have some breaking changes. However, hyper already publicly exposes a dependency onBytes
from the same crate, andAsyncWrite
which also depends onBuf
, so probably not a big deal./cc @scottlamb
The text was updated successfully, but these errors were encountered: