jam1garner / binrw

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

Add a `position_of!` macro to reference earlier fields position #161

Open MrNbaYoh opened 2 years ago

MrNbaYoh commented 2 years ago

This issue is a feature proposal for adding a position_of! macro in the generated code for reading/writing.

#[binrw]
struct Test {
 a: u32,
 b: u32,
 #[br(calc = position_of!(b) + 1000]
 c: u64,
}

Main features

Additional ideas

Concerns

Implementation proposals

The main difficulty is that we need to define a macro that allows us to reference earlier fields only: