Skip to content

Gate TypeVariant and Type behind type_enum feature#522

Open
leighmcculloch wants to merge 12 commits intomainfrom
put-type-enum-behind-feature
Open

Gate TypeVariant and Type behind type_enum feature#522
leighmcculloch wants to merge 12 commits intomainfrom
put-type-enum-behind-feature

Conversation

@leighmcculloch
Copy link
Copy Markdown
Member

@leighmcculloch leighmcculloch commented Mar 30, 2026

What

Move TypeVariant and Type enums out of src/generated.rs into a dedicated src/generated/type_enum.rs file, gated behind a new type_enum cargo feature. Add generator templates (type_enum.rs.jinja, type_enum_definition.rs.jinja) to produce this file. Enable the type feature in cli.

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:

  • stellar-cli
  • stellar-xdr-cli
  • lab

@leighmcculloch leighmcculloch changed the title Gate TypeVariant and Type behind type feature Gate TypeVariant and Type behind type_enum feature Mar 30, 2026
@leighmcculloch leighmcculloch marked this pull request as ready for review April 1, 2026 13:13
Copilot AI review requested due to automatic review settings April 1, 2026 13:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.rs and remove inline inclusion from the generated module root.
  • Update generator output plumbing to render and write the new type_enum.rs file and add it to the generated module list.
  • Wire up the new type_enum feature in crate features/docs/tests and enable it for the cli feature 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants