bytes
bytes copied to clipboard
Consider adding Bytes::try_mut() analog
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?
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.