prost icon indicating copy to clipboard operation
prost copied to clipboard

Config option to use proto `enum`s as Rust `enum`s

Open tkr-sh opened this issue 7 months ago • 3 comments

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 avatar May 05 '25 02:05 tkr-sh

This might be a partial fix to https://github.com/tokio-rs/prost/issues/276 btw

tkr-sh avatar May 05 '25 03:05 tkr-sh

Related PR: #1079

Ten0 avatar May 05 '25 12:05 Ten0

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> https://github.com/tokio-rs/prost/pull/1079#issuecomment-2197525664

tkr-sh avatar May 05 '25 13:05 tkr-sh