Closed octylFractal closed 1 year ago
I don’t think this is a correct change? Codegen does not reorder calc
to occur after all the other fields are read so I am confused by the comment in the commit. Only when writing can you access all fields of the structure, which is what the documentation says now. You can’t do this:
pub struct A {
pub a: u8,
#[br(calc(a + c))] // wrong, `c` does not exist yet
pub b: u8,
pub c: u8,
}
It will error:
error[E0425]: cannot find value `c` in this scope
--> binrw/tests/example.rs:10:23
|
10 | #[br(calc(a + c))]
| ^
| |
| a field by this name exists in `Self`
| help: a local variable with a similar name exists: `a`
Calc works on any field that is present in the struct, since all fields are extracted at the start.