Unseal BytesAdapter
Hi.
I've got my own struct that needs to be needs to be represented by Bytes on the wire to remain compatible.
Currently the process is to copy this structure to a class generated from a .proto and serialize that, however this copy leads to significant performance issues and I'm trying to improve this.
I've noticed that there is a very straightforward trait that allows something to be treated as Bytes... however to my disappointment, it's sealed within a private module.
The interface below is pretty easy for a user to successfully implement. Why is it sealed? Can it be unsealed please?
pub trait BytesAdapter: Default + Sized + 'static {
fn len(&self) -> usize;
/// Replace contents of this buffer with the contents of another buffer.
fn replace_with<B>(&mut self, buf: B)
where
B: Buf;
/// Appends this buffer to the (contents of) other buffer.
fn append_to<B>(&self, buf: &mut B)
where
B: BufMut;
fn is_empty(&self) -> bool {
self.len() == 0
}
}
Could we potentially just leverage BufMut and remove our own trait?
I'm also running into this issue. I've looked into replacing BytesAdapter with BufMut, but Bytes::replace_with requires the ability to reset the buffer, which I don't think you can do with BufMut.