Consider evaluating `calc` before `seek_before`
- Dominant language
- Rust
- Stars
- 853
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Description
Consider evaluating `calc`/`try_calc` before `seek_before`, which would enable the following setup:
```rust
#[bw(stream = st)]
struct Main {
// need to write textures offset at 0xC...
// write other fields
// ...but we don't know the offset until we're here.
// It would be nice if we could get the texture offset this way:
#[bw(try_calc = st.stream_position())]
#[br(temp)]
#[brw(seek_before = SeekFrom::Start(0xC), restore_position)]
textures_offset: u32,
// textures written here...
textures: Textures,
}
```
Currently, `try_calc` is evaluated *after* `seek_before`, so the value of `st.stream_position()` is always `0xC`.
I think it would make sense to switch the order of operations here, considering the argument to `SeekFrom` is either a constant or a field (it wouldn't make sense to use the old stream position, you'd use `SeekFrom::Current` instead), so it shouldn't break existing use cases.
Contributor guide
Research direction
Start by tracing how the `calc`/`try_calc` and `seek_before` attributes are processed for `#[bw]` and `#[brw]` fields. The change is done when `try_calc = st.stream_position()` observes the position before `seek_before`, while existing uses of constant or field-based seek offsets retain their behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- reverse-engineering
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100