-
Notifications
You must be signed in to change notification settings - Fork 507
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
Implement my traits on generated Enum #1185
Comments
I think you are looking for the `prost_build::Config` type. You can configure the generated output to derive strum. You probably want to use https://docs.rs/prost-build/latest/prost_build/struct.Config.html#method.type_attribute
The existence of `Config` is not documented well. Where did you look to find documentation about solving this issue? Are you willing to open a PR to add some example?
9 nov. 2024 14:00:24 Dimitri CORREIA ***@***.***>:
…
*Problem Description*
I'm trying to iterate over the values of an enum generated by Prost, which is something I typically achieve using the Strum crate[https://docs.rs/strum_macros/latest/strum_macros/derive.EnumIter.html] with the *EnumIter* trait. However, since the enum is generated by Prost (prost-build), I can't directly use Strum here.
*What I’ve Tried*
I looked for a way to iterate over the Prost-generated enum, but it seems that this isn’t currently supported, or at least I couldn’t find a method. My workaround idea was to add the enum manually in my Rust code rather than defining it in my *.proto* file, using "Tag Inference for Existing Types" with *use prost::{Enumeration, Message};*. However, this leads to errors since the *.proto* file requires the enum to be defined within it.
*Proposal*
Could we consider adding a feature flag in Prost to allow additional traits on enums, such as an iterator? This would make it easier to iterate over enums generated from *.proto* files without additional workarounds.
I can start to look into creating a PR for this, but I want to be sure it's something that is wanted and possible to achieve.
What are your thoughts on this?
—
Reply to this email directly, view it on GitHub[#1185], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAJZ7OXOKTBVHGA5LBBWMW3Z7YIPLAVCNFSM6AAAAABRPE5LJSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGY2DMMBZHEYTONY].
You are receiving this because you are subscribed to this thread.
[Tracking afbeelding][https://github.com/notifications/beacon/AAJZ7OUI3AY55EEVPF5A2BTZ7YIPLA5CNFSM6AAAAABRPE5LJSWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHJ3OCE5E.gif]
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem Description
I'm trying to iterate over the values of an enum generated by Prost, which is something I typically achieve using the Strum crate with the
EnumIter
trait. However, since the enum is generated by Prost (prost-build), I can't directly use Strum here.What I’ve Tried
I looked for a way to iterate over the Prost-generated enum, but it seems that this isn’t currently supported, or at least I couldn’t find a method. My workaround idea was to add the enum manually in my Rust code rather than defining it in my
.proto
file, using "Tag Inference for Existing Types" withuse prost::{Enumeration, Message};
. However, this leads to errors since the.proto
file requires the enum to be defined within it.Proposal
Could we consider adding a feature flag in Prost to allow additional traits on enums, such as an iterator? This would make it easier to iterate over enums generated from
.proto
files without additional workarounds.I can start to look into creating a PR for this, but I want to be sure it's something that is wanted and possible to achieve.
What are your thoughts on this?
The text was updated successfully, but these errors were encountered: