Skip to content

Added field rename capability#157

Open
tsidea wants to merge 2 commits intojprochazk:mainfrom
tsidea:main
Open

Added field rename capability#157
tsidea wants to merge 2 commits intojprochazk:mainfrom
tsidea:main

Conversation

@tsidea
Copy link

@tsidea tsidea commented Dec 12, 2025

A rename attribute was already present and was being parsed. The only missing link was substituting the field key in the case of structs and the field index in the case of tuples with the alias provided by the rename attribute.

Added a test that verifies the renaming works.

Also added a new section to the README that showcases how to use the rename feature.

Wanted to refactor the rename attribute to work as serde (i.e. #[garde(rename = "name")] ) instead of #[garde(rename("name"))], but did not have the time or expertise to get into it that deep.

Couldn't have done it without the guidance in #127, thank you!

The rename attribute was already present, just had to update the
nested_path invocation in the quote! macro in the emit.rs.
This ensures that the alias will be used instead of the field name or
tuple field index when an alias is present.
@321paranoiawhy
Copy link

Hey, how is it going? Why this feature is no merged?

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