Skip to content
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

Generate From<> cast automatically for protobuf::one #980

Open
gwbres opened this issue Feb 14, 2024 · 0 comments
Open

Generate From<> cast automatically for protobuf::one #980

gwbres opened this issue Feb 14, 2024 · 0 comments

Comments

@gwbres
Copy link

gwbres commented Feb 14, 2024

Hello,

It would be great if the code generator would auto implement From<> anytime it encounters a protobuf::oneof.

I find myself implementing From<> all the time to simplify how to use the auto generated code.

If I understand correctly, anytime we encounter protobuf::oneof we get an object of this form:

pub struct Object {
    #[prost(oneof = "inner::Value", tags = xxx)]
    pub value: ::core:option:Option<inner::Value>,
}

So I wind up writing casts like this all the time

impl From<inner::Value::X> for Object {
   fn from(value: inner::Value::X) -> Object {
      Object {
           value: Some(v),
      }
   }
} 
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

No branches or pull requests

1 participant