I'm using tonic framework, a rust grpc server implementation. In the generated rust code from the proto file, I have a struct which has a field:
#[prost(message, optional, tag="3")]
pub data: ::core::option::Option<::prost_types::Value>,
generated from a protobuff field:
google.protobuf.Value data = 3;
I can't seem to find a way to init data which is type prost_types::Value by converting a struct I have. I'm doing something like:
prost_types::Value::try_from(myOwnsStructVar)
But it does not work. Anyone have used prost_types lib before and know how to encode/convert to prost_types::Value
myOwnsStructVar is a type struct. I need to convert it to prost_types::Struct So then I can do:
prost_types::value::Kind::StructValue(myOwnsStructVarAfterConversiontToProstStruct)
Just from looking at the docs, we can see that
Valueis a struct with a single public fieldkindwhich is of typeOption<Kind>. The docs say that if this field isNonethen that indicates an error. If you look at the docs forKind, then it's apparent this is where the actual data is stored. So if you want to initialize something of typeValuethen you'd want to do something like the following, substituting in the appropriate variant ofKindfor your use case:The reason that your
try_fromsolution didn't work is because there are noTryFromimplementations forValueother than the default blanket implementation.