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

Consider adding Bytes::try_mut() analog #368

Open
rusty-objects opened this issue Jan 29, 2020 · 1 comment
Open

Consider adding Bytes::try_mut() analog #368

rusty-objects opened this issue Jan 29, 2020 · 1 comment

Comments

@rusty-objects
Copy link

rusty-objects commented Jan 29, 2020

In bytes 0.4.x, there was a method Bytes::try_mut() which would allow turning Bytes into (or back into) a BytesMut if it was the only pointer to the memory. This was good for allowing buffer reuse, as a buffer could be created as a BytesMut, updated, frozen to a Bytes, shared around, then recycled as a BytesMut again without having to do anymore allocation. This method pairs well with BytesMut::unsplit(), which allows this crate to be used as the basis of a fairly efficient buffer pool.

Bytes::try_mut() is gone now in 0.5.x.

The exact ergonomics aren't all that important (it could be a method on Bytes or a static method in BytesMut), but the functionality/semantics of being able to turn Bytes into a mutable was pretty useful. Can this be added back?

@rusty-objects rusty-objects changed the title Consider adding Byte::try_mut() analog Consider adding Bytes::try_mut() analog Jan 29, 2020
@TheButlah
Copy link

I am also curious about this, for the exact reason posted above. I had hoped that I could start out with BytesMut, build up my buffer, then freeze() it, pass it around, and once I was finished with it I could reclaim the memory with a try_mut() function to avoid reallocating.

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

No branches or pull requests

2 participants