Make `try_unsplit` method public
The BytesMut::unsplit method can be expensive if the two ranges aren't contiguous and if it requires a memory allocation for a new buffer. This PR makes the existing BytesMut::try_unsplit public so that the user can choose the behaviour if they aren't contiguous.
Related discussion: #287
Actually, I underestimated the amount of prior discussion about this, though nothing appears to have happened on the topic in the past year.
Actually, I underestimated the amount of prior discussion about this, though nothing appears to have happened on the topic in the past year.
No worries, and I understand if you want to keep that discussion open. I originally made this small change before I read that discussion, and it seemed like the most straightforward way of having this functionality in the library as it's already implemented and has a similar interface to BytesMut::unsplit.
@Darksonn Isn't the discussion about unsplit method for Bytes? BytesMut::try_unsplit should be safe to made public:
BytesMutdoesn't use VTable likeBytesdoes - there are only 2 possible underlying storages - Vec and Arc, both of which are handled intry_unsplittry_unsplitis already used through publicunsplitwith some additions to copy data iftry_unsplitfailed.
Just because it doesn't do that today doesn't mean it couldn't in the future.
I don't really have the time to work through the vtable situation any time soon.
Closing this since I don't see a reason to keep it open. We're now just using a custom fork of the bytes library with this patch.