It would be nice if Bytes could be decomposed into its "raw parts" in order to reduce the size overhead of types that wish to support using Bytes as the buffer but already store a base pointer and length information separately, e.g. a multi-dimensional array backed by a Bytes buffer.
To support this, there could be:
impl Bytes {
pub fn to_raw_parts(self) -> (*const u8, usize, BytesOwner) { ... }
pub unsafe fn from_raw_parts(ptr: *const u8, len: usize, owner: BytesOwner) -> Bytes { ... }
}
where BytesOwner includes the data and vtable information.
Users would be required to call from_raw_parts with exactly the values returned from to_raw_parts in order to free the memory. Dropping BytesOwner would leak the memory.
If the maintainers are open to this, I can create a PR.
It would be nice if
Bytescould be decomposed into its "raw parts" in order to reduce the size overhead of types that wish to support usingBytesas the buffer but already store a base pointer and length information separately, e.g. a multi-dimensional array backed by aBytesbuffer.To support this, there could be:
where
BytesOwnerincludes thedataandvtableinformation.Users would be required to call
from_raw_partswith exactly the values returned fromto_raw_partsin order to free the memory. DroppingBytesOwnerwould leak the memory.If the maintainers are open to this, I can create a PR.