-
-
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
Specialize BufList::copy_to_bytes #2413
Conversation
Good idea! The implementation looks right to me (though trickier than I assumed before looking). What do you think of adding a few tests since it's tricky?
|
OK, that makes sense. And yes, these things usually come with more corner cases than expected (this whole implementation doesn't even assume empty buffers are possible somewhere in the middle). During the tests I've noticed this implementation doesn't panic if the request is longer than all the buffers put together. That is probably allowed, because the
So I'd like to know which option you'd prefer. |
The default implementation does panic: https://docs.rs/bytes/1.0.1/src/bytes/buf/buf_impl.rs.html#816 It seems like we can just add the check to the |
Some implementations of the Buf trait have an optimized version (for example Bytes) of copy_to_bytes, opportunistically use that one.
I know. I was just saying that an implementation is probably not required to panic in that situation. As for the check, I was probably stressing too much over the fact that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work, thank you!
Some implementations of the Buf trait have an optimized version (for example Bytes) of copy_to_bytes, opportunistically use that one.
Some implementations of the Buf trait have an optimized version (for
example Bytes) of copy_to_bytes, opportunistically use that one.
For some background, I was implementing a similar type and had a look there and noticed it is not implemented. Or is there some reason why it shouldn't be implemented?