Skip to content

Support zero-allocation encoding into user-provided containers (for compatibility with runtimes like Monoio) #77

@hey-researcher

Description

@hey-researcher

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions