Repository navigation
feat(codegen): add opt-in aliases for mapped Rust types - #320
Merged
Bergmann89 merged 2 commits intoNov 11, 2026
Merged
Conversation
Bergmann89
requested changes
Nov 11, 2026
Bergmann89
left a comment
Owner
There was a problem hiding this comment.
Hey @sundermann,
Thanks, nice feature. Checks pass locally, and with the default (with_alias(false)) nothing changes in the existing output, good.
Before merging:
- Tests:
tests/feature/native_aliasesonly comparesTokenStream::to_string(), so nothing checks that the generated code compiles, and the quick_xml / serde renderers aren't covered even though the description says all renderers are supported. Please switch to the usual layout (generate_testwith compiledexpected/default.rsandexpected/quick_xml.rs), add a root-relative include, and a quick_xml read/write round trip. IdentPath::relative_to: thecrate::/self::handling changes the behaviour for all callers (also non-alias includes and trait paths). It's actually a bug fix of its own (before it producedsuper::crate::...). Please add rows forcrate::a::Bandself::a::Bto the existingrelative_totest table, ideally as a separatefix(...)commit.CustomData::render_aliaslargely repeats the existingTypedefMode::Typedefrendering and is called from four render steps. Could the generator just lower an aliased custom type to the existing typedef path? If the new branch stays, please at least make it match the typedef branch, i.e. withoutextra_attributes.- The error tests should match on the variants (
GeneratorError::MissingCustomAliasTarget,DuplicateTypeName) instead ofto_string().contains(..).
Documentation
- Please remove the README section. If you want to show how to use it, an example crate under
examples/is the better place.
sundermann
force-pushed
the
feat/native-type-aliases
branch
2 times, most recently
from
November 11, 2026 21:53
0c169e0 to
95aa159
Compare
Keep crate-qualified paths anchored to the Rust crate and resolve self-qualified paths from the generated root. This prevents invalid paths such as super::crate::a::B when rendering nested modules.
Preserve schema names and documentation when custom mappings opt into aliases. Lower these mappings to existing typedef data so native values keep their identity and all renderers share the normal typedef implementation. Keep mapped paths and custom generation hooks intact, report missing targets and generated-name collisions, and provide a runnable native-alias example. Document alias target metadata and path resolution, and distinguish native aliases from direct mappings in custom type equality and hashing.
sundermann
force-pushed
the
feat/native-type-aliases
branch
from
November 11, 2026 22:22
95aa159 to
9fb5246
Compare
Bergmann89
approved these changes
Nov 11, 2026
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.
Adds optional aliases that preserve schema names and documentation for types mapped to existing Rust types. This keeps schema types available in the generated public API without introducing wrappers.
Changes
CustomMeta::with_alias(true)to generate schema-named aliases and reference them in generated fields. Preserve documentation, configured renames, namespace/schema placement, and distinct declarations during deduplication.ReferenceData/TypedefMode::Typedefrepresentation in the generator. All four type renderers reuse their existing typedef handling, including its treatment of attributes, and custom generator hooks still run.self::/crate::path rules oninclude_from.CustomMetaequality and hashing, with regression coverage for mapping identity and hooks running once with aliases enabled or disabled.IdentPath::relative_toanchor correction in a separatefix(codegen)commit. Add rows to its existing test table forcrate::a::Bandself::a::Bat the generated root and in nested modules. The crate-qualified case fails with an assertion before the fix.examples/native_aliasescrate.Public API changes:
CustomMetagains thealiasfield, andGeneratorErrorgainsMissingCustomAliasTarget. DirectCustomMetainitializers and exhaustive generator-error matches must account for these additions.CustomMetaequality and hashing distinguish alias-enabled mappings from direct mappings. Alias generation is disabled by default.Checklist
update-expectationsand reviewedcargo fmt,cargo clippyandcargo testpass (see CONTRIBUTING.md)native_aliases, andcargo build -p benchmark --releasepass