tokio-rs / bytes

Utilities for working with bytes
MIT License
1.86k stars 278 forks source link

Feature request: fallible version of `BytesMut::unsplit` (i.e. make `BytesMut::try_unsplit` public) #702

Open aochagavia opened 4 months ago

aochagavia commented 4 months ago

I'm using BytesMut::unsplit in a project and would like to raise an error when the bytes cannot be unsplitted, instead of silently copying. An Err(_) would let me know I messed up somewhere, so I can go fix the problem.

Reading the source code, I came across try_unsplit, which seems to do exactly what I need, but is private. Have you considered making it public? Or is there a suitable workaround for people like me, who want to guarantee that no data is ever copied from one BytesMut to the other?

In case it's relevant, below is the code for try_unsplit that I think could be made public:

https://github.com/tokio-rs/bytes/blob/cb7f8449b5efc7022dc592b3a1d7dd33079f4c8f/src/bytes_mut.rs#L908-L926

Darksonn commented 4 months ago

Duplicate of #287.

aochagavia commented 4 months ago

Just in case: the linked issue seems to be about Bytes, so I assumed it didn't apply to BytesMut.