tafia / quick-protobuf

A rust implementation of protobuf parser
MIT License
446 stars 82 forks source link

Custom derive vs proto comments #231

Open nerdrew opened 1 year ago

nerdrew commented 1 year ago

I have two changes on my personal repo for adding attributes to structs. One is to allow custom structs via build flags while the other adds support for magic proto comments that are included in the generated code.

I've found the proto comments to be easier to maintain and nicer to work with. Thoughts on these two approaches? I'll open a PR for adding proto comment support if others like the "API".

snproj commented 1 year ago

Hi! This sounds like a good idea to me; I also personally prefer the proto comments approach. I can think of some pros and cons to proto comments:

Pros

Compared to build flags, as you say they look easier to maintain and work with. We can:

Con

On the other hand, one downside I can think of for proto comments is that we have to actually modify the proto file itself. Proto files that at some point have been touched by a user of pb-rs may now be marked with what is essentially noise to users of literally any other compiler (even other Rust proto compilers).

Whether this will be an issue I think will depend on the use case of the proto file itself and whether it's very specific in its circulation (e.g. internally within a company), or if it will be exposed to the public at large. Thoughts?

Unless we can convince others to use the comment convention 👀 🤔

Implementation

Looking at the code, I'm wondering whether it's a good idea to implement this in a more generalized way, so that:

What do you think?

On a side note, the addition of EnumField is nice; I was about to do something like that in order to properly implement deprecated fields for enums.