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]...
Currently a
Packetcan only contain aVec<u8>. It would be great if it could work with anArc<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
Packetwithout copying all the data (if the cloning e.g. happens in theDecoderonly for being able to have it around a little bit longer than the call where the&Packetis passed).From my understanding the data of a
Packetis always immutable currently, but if this is not generally true thenAsMut<[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
Arcwould be another heap allocation, but as the data itself is already heap allocated unless you use a&'static [u8]...