Open TheButlah opened 1 month ago
It there a way to get a BytesMut
from Bytes
without copying it?
I am on my phone atm, but considering the underlying QUIC library returns Bytes
I am wondering if that's trivially feasible
AFAIK, no, there isn't a way. There is a is_unique
function, but I don't think it can be used for the purpose of converting to a BytesMut. I could be wrong though.
I am afraid so. Considering the QUIC connection returns a datagram as Bytes
here, the only possibility is to copy the data (even if the Bytes
is unique), I guess
There's an adjacent issue for this in the Quinn repo: https://github.com/quinn-rs/quinn/issues/1173
Some use cases, such as using datagrams with serde via
tokio_serde::Framed
, require that messages received from the peer areBytesMut
instead ofBytes
. Currently,Connection::receive_datagram()
returns aDatagram
which itself can only give youBytes
, so the user of the API first needs to clone the data to get exclusive access to a buffer.It would be nice if
receive_datagrams
instead returned aBytesMut
, providing more performance for use cases like mine where I actually need exclusive access to the buffer.