Skip to content

Config option to use proto enums as Rust enums - #1278

Open
tkr-sh wants to merge 11 commits into
tokio-rs:masterfrom
tkr-sh:master
Open

Config option to use proto enums as Rust enums#1278
tkr-sh wants to merge 11 commits into
tokio-rs:masterfrom
tkr-sh:master

Conversation

@tkr-sh

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

Copy link
Copy Markdown

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

tkr-sh commented May 5, 2025

Copy link
Copy Markdown
Author

This might be a partial fix to #276 btw

@Ten0

Ten0 commented May 5, 2025

Copy link
Copy Markdown

Related PR: #1079

@tkr-sh

tkr-sh commented May 5, 2025

Copy link
Copy Markdown
Author

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