You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In bytes0.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?
The text was updated successfully, but these errors were encountered:
rusty-objects
changed the title
Consider adding Byte::try_mut() analog
Consider adding Bytes::try_mut() analog
Jan 29, 2020
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.
In
bytes
0.4.x
, there was a methodBytes::try_mut()
which would allow turningBytes
into (or back into) aBytesMut
if it was the only pointer to the memory. This was good for allowing buffer reuse, as a buffer could be created as aBytesMut
, updated, frozen to aBytes
, shared around, then recycled as aBytesMut
again without having to do anymore allocation. This method pairs well withBytesMut::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 inBytesMut
), but the functionality/semantics of being able to turnBytes
into a mutable was pretty useful. Can this be added back?The text was updated successfully, but these errors were encountered: