jam1garner / jam1garner/binrw

Writing enums: pre_assert?

Open
#272 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

confusing api enhancement
Dominant language
Rust
Stars
853
Forks
56
PR merge metrics
No merged PRs in 30d

Description

I have code like this:

```
#[derive(BinRead, BinWrite, Debug)]
#[brw(import(message_type: u8))]
enum MessageData {
#[br(pre_assert(message_type == 0x0u8))] Nil {
},
...
}
```

`bw` / `brw` don't allow `pre_assert` so they can't serialize this. Is there a way to reverse parsing an enum like this? Is it feasible to implement `pre_assert` for `brw`?... I don't _think_ using `assert` is correct.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named. Start by tracing how enum attributes such as #[br(pre_assert(...))] and #[brw(...)] are handled, then compare the parsing and writing paths. Done means determining whether pre_assert can support brw serialization and documenting or testing the resulting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.