Generate Rust enum shells from spec enumerations#100
Merged
Conversation
This was referenced Jun 10, 2026
Merged
Member
Author
This was referenced Jun 10, 2026
Member
Author
Merge activity
|
This PR teaches the generator to emit Rust `enum` definitions from the spec's `EnumerationSpec` entries, replacing 9 previously hand-written enum shells with generated ones. The spec carries enumerations at the category level (today they all live under `shared`), so discovery is a simple walk over `category.enumerations` — no extra config and no additions to the override surface.
Each generated enum gets the standard derive set (`Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize`) plus `#[serde(rename_all = "camelCase")]`. Variants are `pascalCase(spec name)` in declaration order, with enum-level and variant-level docs propagated from the spec. The generator deliberately does not emit `#[derive(Default)]`: the spec doesn't carry a "default variant" notion, so any required `Default` lives in a hand-written companion file alongside the generated shell — the same generated-type / hand-written-impls split already used for `Number`.
Reconciling the spec with the existing Rust crate required one breaking rename: `Endianness::{Big, Little} → Endianness::{Be, Le}`, since the generator derives variant names directly from the spec's `[be, le]` rather than carrying a per-enum override. The hand-written `TryFrom` impls still accept both the short and long forms as input. `NumberFormat` variant ordering also shifts from semantic to alphabetic (matching spec order); no `match` site relies on the old ordering. `instruction_node.rs`, `instruction_status_node.rs`, `shared/bytes_encoding.rs`, and the `type_nodes/{number,pre_offset,post_offset}_type_node.rs` files each lose their inline enum definition and keep only the bespoke impls (constructors, `TryFrom`, `Default`) the spec can't express; two new files in `shared/` hold the `Default` impls for `InstructionLifecycle` and `OptionalAccountStrategy` so the per-type generated/hand-written symmetry stays clean.
Workspace-wide: 1006 cargo tests pass unchanged, fmt and clippy stay clean, `pnpm test` grew by 6 enumPage tests (113 → 119), and `pnpm generate` round-trips deterministically.
b97591f to
407b222
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR teaches the generator to emit Rust
enumdefinitions from the spec'sEnumerationSpecentries, replacing 9 previously hand-written enum shells with generated ones. The spec carries enumerations at the category level (today they all live undershared), so discovery is a simple walk overcategory.enumerations— no extra config and no additions to the override surface.Each generated enum gets the standard derive set (
Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize) plus#[serde(rename_all = "camelCase")]. Variants arepascalCase(spec name)in declaration order, with enum-level and variant-level docs propagated from the spec. The generator deliberately does not emit#[derive(Default)]: the spec doesn't carry a "default variant" notion, so any requiredDefaultlives in a hand-written companion file alongside the generated shell — the same generated-type / hand-written-impls split already used forNumber.Reconciling the spec with the existing Rust crate required one breaking rename:
Endianness::{Big, Little} → Endianness::{Be, Le}, since the generator derives variant names directly from the spec's[be, le]rather than carrying a per-enum override. The hand-writtenTryFromimpls still accept both the short and long forms as input.NumberFormatvariant ordering also shifts from semantic to alphabetic (matching spec order); nomatchsite relies on the old ordering.instruction_node.rs,instruction_status_node.rs,shared/bytes_encoding.rs, and thetype_nodes/{number,pre_offset,post_offset}_type_node.rsfiles each lose their inline enum definition and keep only the bespoke impls (constructors,TryFrom,Default) the spec can't express; two new files inshared/hold theDefaultimpls forInstructionLifecycleandOptionalAccountStrategyso the per-type generated/hand-written symmetry stays clean.Workspace-wide: 1006 cargo tests pass unchanged, fmt and clippy stay clean,
pnpm testgrew by 6 enumPage tests (113 → 119), andpnpm generateround-trips deterministically.