Skip to content
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

BytesMut should impl IntoBuf #158

Closed
carllerche opened this issue Sep 28, 2017 · 5 comments · Fixed by #260
Closed

BytesMut should impl IntoBuf #158

carllerche opened this issue Sep 28, 2017 · 5 comments · Fixed by #260
Milestone

Comments

@carllerche
Copy link
Member

See: tokio-rs/tokio-io#72

@carllerche carllerche added this to the v0.5 milestone Nov 7, 2017
@seanmonstar
Copy link
Member

It looks like this is already the case in 0.4.x. Should it still return a Cursor<BytesMut>? Or should BytesMut implement Buf directly instead?

@carllerche
Copy link
Member Author

BytesMut should impl Buf directly. Maybe it does already? Either way, it has the capability to do so.

@YetAnotherMinion
Copy link
Contributor

YetAnotherMinion commented Jun 1, 2018

I ran into problems with impl Buf for BytesMut. Specifically when removing advance from BytesMut and using the Buf's impl reveals that there are conflicting take methods on Buf and BytesMut.

BytesMut::take takes everything and passes ownership into a new BytesBuf, while Buf::take allows configuring how much is taken, but during the transferring ownership instead portion of its act, it consumes self, basically acting like truncate (without changing the underlying storage).

Can someone here give me more background information about the use case for the two different functions? I do not think the functionality of the two can be merged because they are doing fundamentally different things with ownership.

The simplest solution I can think of is just renaming the functions. I think that BytesMut::take should keep the name, and Buf::take should be renamed to something like Buf::prefix (and Take to Prefix).

@mzabaluev
Copy link
Contributor

I, too, was confused with the disparate take methods. But my solution for this would be to replace BytesMut::take with a trait API that would work on both Bytes and BytesMut (and their UTF-8 counterparts StrChunk/StrChunkMut being incubated in that crate) and allow the user to specify a range to take. So received_bytes.take() would be received_bytes.take_range(..).

@mzabaluev
Copy link
Contributor

So received_bytes.take() would be received_bytes.take_range(..).

I have now distilled that into crate range-split.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants