Gate TypeVariant and Type behind type_enum feature#522
Open
leighmcculloch wants to merge 12 commits intomainfrom
Open
Gate TypeVariant and Type behind type_enum feature#522leighmcculloch wants to merge 12 commits intomainfrom
type_enum feature#522leighmcculloch wants to merge 12 commits intomainfrom
Conversation
type featuretype_enum feature
… manual `Default` impls with `#[default]` attribute on enums, added clippy allows, and minor test fixes. regenerate code and use #[default] on enums
…ious commit message. Let me look more carefully. gate Type/TypeVariant behind type_enum feature
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new type_enum Cargo feature to gate the generated dynamic TypeVariant / Type APIs, and moves their generation into a dedicated type_enum.rs module to reduce default build time and binary size for users who don’t need runtime-selected type dispatch.
Changes:
- Add generator templates to emit
src/generated/type_enum.rsand remove inline inclusion from the generated module root. - Update generator output plumbing to render and write the new
type_enum.rsfile and add it to the generated module list. - Wire up the new
type_enumfeature in crate features/docs/tests and enable it for theclifeature set.
Reviewed changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| xdr-generator-rust/generator/templates/type_enum.rs.jinja | Adds #[cfg(feature = "type_enum")] gating around generated type-enum items. |
| xdr-generator-rust/generator/templates/type_enum_definition.rs.jinja | New wrapper template to generate type_enum.rs with use super::*;. |
| xdr-generator-rust/generator/templates/mod.rs.jinja | Stops inlining the type-enum template into the generated root module. |
| xdr-generator-rust/generator/src/output.rs | Adds TypeEnumDefinitionTemplate; removes type-enum data from ModTemplate. |
| xdr-generator-rust/generator/src/generator.rs | Writes type_enum.rs alongside per-type files and appends a type_enum module entry. |
| xdr-generator-rust/generator/src/tests/generator.rs | Updates assertion to expect type_enum cfg gating in generated output. |
| tests/tx_small.rs | Gates tests/imports that use Type/TypeVariant behind feature = "type_enum". |
| tests/tx_auths.rs | Refactors slice construction to avoid cloning (uses slice::from_ref). |
| src/lib.rs | Documents type_enum feature and relaxes clippy lints for generated module. |
| README.md | Documents type_enum feature in the feature list. |
| Cargo.toml | Adds type_enum feature and enables it as part of cli. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
What
Move
TypeVariantandTypeenums out ofsrc/generated.rsinto a dedicatedsrc/generated/type_enum.rsfile, gated behind a newtype_enumcargo feature. Add generator templates (type_enum.rs.jinja,type_enum_definition.rs.jinja) to produce this file. Enable thetypefeature incli.Why
These enums enumerate every XDR type, making them very large. Putting them behind a feature flag lets users who don't need dynamic type dispatch avoid the compile-time and binary-size cost. The majority of our uses of the Rust xdr lib do not require these types. Removing them from the default build almost halves the default build build time.
The places the type enum get used are: