Generate Rust type nodes#103
Merged
Merged
Conversation
This was referenced Jun 10, 2026
Merged
Member
Author
This was referenced Jun 10, 2026
Member
Author
Merge activity
|
This PR generates 21 of the 28 `type`-category nodes from `@codama/spec`, completing first-class generation support for all 8 spec categories. The 7 nestable wrappers (`fixedSize`, `sizePrefix`, `pre/postOffset`, `sentinel`, `hiddenPrefix/Suffix`) and the four type-category unions stay hand-written, since they carry generic variant types, a cross-category Link member, and bespoke `TryFrom` bridges that don't fit the standard renderers — and they're the natural deletion boundary if a future spec drops nested unions.
The generator gains a `NodeMacroFlavor` classifier (`nodeFlavor.ts`) that picks the emission macro per node from the spec: `nestedTypeNode.wrappers` are skipped, `enumVariantTypeNode` members and `structFieldTypeNode` get `#[node]`, and other type nodes get `#[type_node]`. `CategoryRouting` gains an `emitUnions` flag so `type` skips its bespoke unions, and `struct` joins the Rust keyword set so `enumStructVariantTypeNode.struct` renders as `r#struct`.
Reconciliation is mostly contained to `codama-nodes/src/type_nodes/`. Spec-driven type changes: `amountTypeNode.decimals → u32`, the enum-variant `discriminator → Option<u32>`, and `optionTypeNode.fixed → Option<bool>`. The box-all-union rule boxes `array/map/set.count → Box<CountNode>` and `structFieldTypeNode.{type, default_value}`, which cascades into a few `codama-attributes`/`codama-koroks`/`codama-korok-visitors` files and their tests. The hand-written nestable nodes are left untouched.
1008 cargo tests pass unchanged; `pnpm test` grew by 8 to 148; fmt, clippy, and the `pnpm generate` round-trip stay clean. The override surface is unchanged.
afc7a35 to
9937be4
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 generates 21 of the 28
type-category nodes from@codama/spec, completing first-class generation support for all 8 spec categories. The 7 nestable wrappers (fixedSize,sizePrefix,pre/postOffset,sentinel,hiddenPrefix/Suffix) and the four type-category unions stay hand-written, since they carry generic variant types, a cross-category Link member, and bespokeTryFrombridges that don't fit the standard renderers — and they're the natural deletion boundary if a future spec drops nested unions.The generator gains a
NodeMacroFlavorclassifier (nodeFlavor.ts) that picks the emission macro per node from the spec:nestedTypeNode.wrappersare skipped,enumVariantTypeNodemembers andstructFieldTypeNodeget#[node], and other type nodes get#[type_node].CategoryRoutinggains anemitUnionsflag sotypeskips its bespoke unions, andstructjoins the Rust keyword set soenumStructVariantTypeNode.structrenders asr#struct.Reconciliation is mostly contained to
codama-nodes/src/type_nodes/. Spec-driven type changes:amountTypeNode.decimals → u32, the enum-variantdiscriminator → Option<u32>, andoptionTypeNode.fixed → Option<bool>. The box-all-union rule boxesarray/map/set.count → Box<CountNode>andstructFieldTypeNode.{type, default_value}, which cascades into a fewcodama-attributes/codama-koroks/codama-korok-visitorsfiles and their tests. The hand-written nestable nodes are left untouched.1008 cargo tests pass unchanged;
pnpm testgrew by 8 to 148; fmt, clippy, and thepnpm generateround-trip stay clean. The override surface is unchanged.