[project] Distinguish structs/union/enums by joshlf · Pull Request #2857 · google/zerocopy

@joshlf mentioned this pull request

Dec 22, 2025

gemini-code-assist[bot]

@joshlf joshlf changed the title [project] Use -1 for struct/union VARIANT_ID [project] Distinguish structs/union/enums

Dec 22, 2025

@joshlf

For the `HasField` `VARIANT_ID` and `FIELD_ID` constants, use `i128`
instead of `u128`. For structs and unions, set `VARIANT_ID = -1` and
`VARIANT_ID = -2` (respectively) instead of 0. This ensures that we will
never accidentally confuse the first (ie, 0th) variant of an enum with a
struct or union. It also paves the way for us to define methods which
only support a subset of structs/unions/enums.

Makes progress on #196, #2856

gherrit-pr-id: G03596047b3e8a9931799295d1e707540561c4e46

@joshlf joshlf deleted the G03596047b3e8a9931799295d1e707540561c4e46 branch

December 22, 2025 20:06