jam1garner / binrw

A Rust crate for helping parse and rebuild binary data using ✨macro magic✨.
https://binrw.rs
MIT License
620 stars 36 forks source link

Add pad_size_to for struct types #250

Open czaloj opened 8 months ago

czaloj commented 8 months ago

pad_size_to on a struct should be able to reference import, temp variables, and generated fields.

Added StructGenerator::wrap_pad_size and smaller BinWrite implementation

3 new unit tests that check reading, one for write

csnover commented 6 months ago

I tried to update this PR to include enum but don’t have the bandwidth. It is confusing only to apply this to struct when enum is the same thing. Any chance you can make this change?

csnover commented 6 months ago

Other feedback based on my trying to include enum: Being able to use a field from inside a struct to define the struct size is convenient for formats where the object size is stored that way, but also somewhat problematic because it violates some notion of scoping rules. As a result, code has to be emitted from a place where the field variables are available and can’t be done just once somewhere closer to generate.

ismell commented 1 month ago

Any update on this? This functionality would be very useful in making the definitions a lot clearer.

csnover commented 1 month ago

A volunteer is needed to handle the enum case.