I'm trying to create an EthernetFrame struct. In C I could use the flexible array member as the last field in the struct. How do I do this in Rust? Also how do I create an instance of this struct from the Vec<u8> buffer I have? (Since pointer casting only works on primitive types in rust.)
The total size of the Payload can vary between 50 bytes to 1504 bytes.
Right thanks!. How about creating a new instance of the struct from the Vec<u8> buffer?(The capacity of the vector matches with the size of the EthernetFrame struct)
Actually flexible member with "coerce unsized" (Coercions - The Rustonomicon). Sorry, I can't find a clear example for this, but you can have a struct that ends with a slice and uses a fat pointer to track size of that slice.
A less adventurous arrayvec that preallocates max space, and tracks how much is used. It behaves like Vec, but doesn't cause heap allocation. It does have its own representation, so you can't cast raw packed data to it, so that's not for C-style lazy parsing.