stepancheg / rust-protobuf

Rust implementation of Google protocol buffers
MIT License
2.81k stars 382 forks source link

impl From for MessageField for convenience #693

Closed jkalez closed 9 months ago

jkalez commented 11 months ago

I have found that constructing various messages often leads to creating MessageField types explicitly. For example, the following struct may be generated:

struct MyStruct {
    pub some_field: MessageField<MyOtherStruct>,
    ...
    pub special_fields: SpecialFields
}

I often initialize this as follows:

let s =  MyStruct {
    some_field: MessageField::some(MyOtherStruct { <blah> }),
   ...
};

This PR would allow users to use the blanket provided implementation of Into by deriving From, enabling this simpler syntax:

let s =  MyStruct {
    some_field: MyOtherStruct { <blah> }.into(),
    ...
};
stepancheg commented 10 months ago

This PR adds code commented out.

stepancheg commented 9 months ago

Closing this PR, please reopen if this change is still needed and PR is fixed.