-
Notifications
You must be signed in to change notification settings - Fork 469
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
Add visitor methods to Config in prost-build #816
Comments
This is a really interesting idea! I think its a bit complicated and exposes a lot of internal details so I am not sure if its the right approach. Would be interesting to see a comparison on how other languages handle similar sort of features for their code gen. |
Regarding other languages: in a sense, Prost is 'compiling' (or transpiling) the proto to Rust. The visitor pattern is pretty common in compilers, in general. In terms of internals: I was just reusing the pattern used in the
In retrospect, this is much cleaner than passing a buf parameter. WIth that a Perhaps the actual codegen pass could just be added as a set of visitors. One weakness of the visitor pattern for this is order of visitors might matter. I think i ran into a thing where a One potential alternative might be proc_macros. I don't know how that would work, but they take a TokenStream in, and apply arbitrary modifications (vaguely like this). |
The type_attribute, field_attribute is powerful but sometimes constraining. Previously, identifying enums vs messages was impossible due to this (see: #784). There are other customer-specific patterns that can't be turned into '*_attribute' methods.
I believe a type_visitor and field_visitor (and maybe message_visitor, enum_visitor) method should be added to Config. Then customers can do something like
I did some research on implementation details in #586
Thanks!
The text was updated successfully, but these errors were encountered: