It would be very helpful to have the ability to encode data directly into a user-provided, owned container, rather than being limited to buffer.encode(…) -> &'_ [u8].
Reasoning:
Some async runtimes, such as monoio, require owned containers for I/O operations. Currently, code like the following does not work because buffer.encode returns a borrowed slice:
let data = buffer.encode(&my_data);
let (res, _) = socket.send(data).await;
It would be ideal if the API allowed encoding directly into a user-provided buffer, for example:
let mut my_buf = Vec::with_capacity(1024);
…
bitcode::encode_to(&my_data, &mut my_buf);
let (res, ret_my_buf) = socket.send(my_buf).await;
my_buf = ret_my_buf;