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

feat(derive): Introduce flatten attribute #118

Merged
merged 6 commits into from
Jan 4, 2023

Conversation

howardjohn
Copy link
Contributor

Fixes #117

This introduces a new attribute to the derive code for to flatten. This matches https://serde.rs/attr-flatten.html.

This seems to work, but I have some concern that if there are duplicate fields we end up encoding all of them which may make things go awry. Checking this is hard since we would need to lookup the type, which I am not sure how to do...

@howardjohn howardjohn changed the title Introduce attribute for derive Introduce flatten attribute for derive Dec 14, 2022
@mxinden
Copy link
Member

mxinden commented Dec 29, 2022

This seems to work, but I have some concern that if there are duplicate fields we end up encoding all of them which may make things go awry. Checking this is hard since we would need to lookup the type, which I am not sure how to do...

If I am not mistaken, serde isn't able to handle duplicate fields at compile time either.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Great work. Thanks @howardjohn. I have a couple of questions and comments. Overall this looks good to me.

We can release this as a patch release. Would you mind bumping the patch version in derive-encode/Cargo.toml and provide a changelog entry in CHANGELOG.md?

derive-encode/src/lib.rs Outdated Show resolved Hide resolved
derive-encode/src/lib.rs Outdated Show resolved Hide resolved
derive-encode/src/lib.rs Outdated Show resolved Hide resolved
@mxinden mxinden changed the title Introduce flatten attribute for derive feat(derive): Introduce flatten attribute Dec 29, 2022
Signed-off-by: John Howard <[email protected]>
Signed-off-by: John Howard <[email protected]>
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Wonderful. Thanks for the follow-up. One more thing for the changelog. Otherwise this is ready to go. Happy to cut a release right once this is merged.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
@mxinden
Copy link
Member

mxinden commented Jan 4, 2023

For legal reasons you need to add a sign-off line to each of your commits :(, see failing CI check. Mind doing a force push. Sorry for the inconvenience @howardjohn.

Signed-off-by: John Howard <[email protected]>
@howardjohn
Copy link
Contributor Author

No problem, updated

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Thanks for bearing with me.

@mxinden mxinden merged commit 9141c11 into prometheus:master Jan 4, 2023
@mxinden
Copy link
Member

mxinden commented Jan 4, 2023

Tagged and published.

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.

Add #[flatten] directive for derivation of nested structs
2 participants