Skip to content

Derive from_variants for FFI oneof fields - #738

Merged
ladvoc merged 4 commits into
mainfrom
ladvoc/from-variants
Oct 15, 2025
Merged

Derive from_variants for FFI oneof fields#738
ladvoc merged 4 commits into
mainfrom
ladvoc/from-variants

Conversation

@ladvoc

@ladvoc ladvoc commented Oct 11, 2025

Copy link
Copy Markdown
Contributor

This PR derives from_variants on generated enums representing oneof fields from the FFI protocol, allowing a message to be converted into its corresponding oneof variant using into. This results in a significant boilerplate reduction in the FFI implementation.

@ladvoc
ladvoc marked this pull request as ready for review October 11, 2025 01:32

@1egoman 1egoman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense to me!

Only one minor thought - how common are enum field that contain the same struct, resulting in conflicts in the from_variants implementations? Is it worth trying to think about some sort of more scalable solution than just piecemeal adding from_variants_skip_field to handle these or are they fairly uncommon?

@ladvoc

ladvoc commented Oct 15, 2025

Copy link
Copy Markdown
Contributor Author

Makes sense to me!

Only one minor thought - how common are enum field that contain the same struct, resulting in conflicts in the from_variants implementations? Is it worth trying to think about some sort of more scalable solution than just piecemeal adding from_variants_skip_field to handle these or are they fairly uncommon?

Good point! I did think about this, but I think this situation is pretty uncommon. A more scalable solution would be creating a custom proc_macro, but I think we should cross that bridge later if it becomes an issue.

@ladvoc
ladvoc merged commit 82ba55d into main Oct 15, 2025
10 of 11 checks passed
@ladvoc
ladvoc deleted the ladvoc/from-variants branch October 15, 2025 03:29
@github-actions github-actions Bot mentioned this pull request Oct 15, 2025
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