Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix patching of nested structs #22

Merged
merged 2 commits into from
Aug 25, 2023

Conversation

mirosval
Copy link
Contributor

@mirosval mirosval commented Aug 24, 2023

when nesting structs, the patches should also use nested patches instead of the original nested structs, otherwise a patch with a nested structure can not be deserialized from json (the original non-patched struct is used to deserialize the json and if fields are missing, it fails)

this pr solves the problem by introducing #[patch_name = ] attribute that can be added to fields. The name should point to the patch structure that should be used instead of the original. This attribute then causes 2 things to happen:

  1. The new name is used for the type of the field in generated code
  2. It generates different methods in the Patch traits based on if the fields are renamed or not

This should fix #21

when nesting structs, the patches should also use nested patches instead of the original nested structs, otherwise a patch with a nested structure can not be deserialized from json (the original non-patched struct is used to deserialize the json and if fields are missing, it fails)

this pr solves the problem by introducing #[patch_name = <name>] attribute that can be added to fields. The name should point to the patch structure that should be used instead of the original. This attribute then causes 2 things to happen:
1. The new name is used for the type of the field in generated code
2. It generates different methods in the Patch traits based on if the fields are renamed or not
Copy link
Owner

@yanganto yanganto left a comment

Choose a reason for hiding this comment

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

Awesome. Just a little lint issue needs your hand.

struct-patch-derive/src/lib.rs Outdated Show resolved Hide resolved
@yanganto yanganto merged commit a166bc5 into yanganto:main Aug 25, 2023
2 of 3 checks passed
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.

Nested Structs
2 participants