You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently if you have an enum field marked as optional, prost wraps the i32 field in an Option as with other scalar values. However, the generated getter in this case still returns MyEnum instead of Option<MyEnum>, silently converting a None into the default value. This burned me recently, and it's also inconsistent with the fact that the i32 fields are wrapped in Option.
The text was updated successfully, but these errors were encountered:
@caspermeijn I have the same issues, which make me have to use a trick to convert from Option. I checked the source code and found that it has some strange behavior in
It returns a default value with Kind::Optional. I think that with Kind::Optional, we should return None if it's not set.
I tried to change the above code, but it affected a lot of other code, because #[prost(optional)] is used a lot.
For example, with
pubstructFieldDescriptorProto{#[prost(string, optional, tag = "1")]pubname:::core::option::Option<::prost::alloc::string::String>,
Instead of checking if name is Some or None, some other code uses a function from a code macro like:
I think we should have another function if we need to get name with a fallback to a default value, like name_fallback_default. As I'm new to working with Prost source code, I'm not familiar with it enough to know the best direction. Could you please give me some advice on this case?
Ps: I just implemented the patch in my fork. Can you take a look? giangndm#1
Currently if you have an enum field marked as
optional
,prost
wraps thei32
field in anOption
as with other scalar values. However, the generated getter in this case still returnsMyEnum
instead ofOption<MyEnum>
, silently converting aNone
into the default value. This burned me recently, and it's also inconsistent with the fact that thei32
fields are wrapped inOption
.The text was updated successfully, but these errors were encountered: