Skip to content

Config option to use proto enums as Rust enums #1278

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

tkr-sh
Copy link

@tkr-sh tkr-sh commented May 5, 2025

By default, protos enums are converted to Rust i32. Which can be annoying / not convenient.

I created a new Config field - proto_enum_to_rust_enum - that, when activated, converts proto's enums into Rust's enum instead of i32,
The data transferred over the wire is exactly the same as i32. (See: prost-derive/src/field/enum_typed.rs)


Not sure where to put the test in prost-build/src/code_generator.rs?

@tkr-sh
Copy link
Author

tkr-sh commented May 5, 2025

This might be a partial fix to #276 btw

@Ten0
Copy link

Ten0 commented May 5, 2025

Related PR: #1079

@tkr-sh
Copy link
Author

tkr-sh commented May 5, 2025

Yes! But this one is really easy to implement since it keeps the same declaration of enums, it's just that the types used in messages (in the Rust representation) are enums.
I think that it could be a nice addition, even to #1079 in case you don't want to handle open enums.
Also, would be really easy to add support for Result<_, i32> #1079 (comment)

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