Skip to content

Allow creating Packets from non-Vec data without copying / zero-copy cloning #53

@sdroege

Description

@sdroege

Currently a Packet can only contain a Vec<u8>. It would be great if it could work with an Arc<AsRef<[u8]>> or similar instead (or in addition via an enum for the two cases).

This would allow to fill packets with (read-only) data from other places and would also allow to clone the Packet without copying all the data (if the cloning e.g. happens in the Decoder only for being able to have it around a little bit longer than the call where the &Packet is passed).

From my understanding the data of a Packet is always immutable currently, but if this is not generally true then AsMut<[u8]> might also be an option.

I'd be happy to implement this if we end up with a nice design here. Main disadvantage of using an Arc would be another heap allocation, but as the data itself is already heap allocated unless you use a &'static [u8]...

Metadata

Metadata

Assignees

No one assigned

    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