This is a syntax error because a struct cannot have a field named with the keyword type
. I know this is worked around for normal message fields by renaming the field to "field_type" but it doesn't seem to do that when the field is in a oneof. I tried it with both proto3 and proto2 and had the same results.
On the topic, something I am curious about: is it sufficient to simply rename the field "field_type" in the Rust code? Will it still be serialized as "type"?
I tried a simple test where the field was actually named "field_type" in the proto file and the only thing that seemed to change in the generated Rust file was the contents of the static file_descriptor_proto_data
array, which makes me think rust-protobuf is smart enough not to call the field "field_type" in the serialized format when it was only renamed to avoid the syntax error. I'd appreciate if that could be confirmed, though.
43c43
< // optional string type = 1;
---
> // optional string field_type = 1;
199,208c199,209
< 0x0a, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x14, 0x0a, 0x04,
< 0x54, 0x65, 0x73, 0x74, 0x12, 0x0c, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01,
< 0x28, 0x09, 0x4a, 0x70, 0x0a, 0x06, 0x12, 0x04, 0x00, 0x00, 0x04, 0x01, 0x0a, 0x08, 0x0a, 0x01,
< 0x0c, 0x12, 0x03, 0x00, 0x00, 0x12, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x00, 0x12, 0x04, 0x02, 0x00,
< 0x04, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x02, 0x08, 0x0c, 0x0a, 0x0b,
< 0x0a, 0x04, 0x04, 0x00, 0x02, 0x00, 0x12, 0x03, 0x03, 0x02, 0x12, 0x0a, 0x0d, 0x0a, 0x05, 0x04,
< 0x00, 0x02, 0x00, 0x04, 0x12, 0x04, 0x03, 0x02, 0x02, 0x0e, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00,
< 0x02, 0x00, 0x05, 0x12, 0x03, 0x03, 0x02, 0x08, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00,
< 0x01, 0x12, 0x03, 0x03, 0x09, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x03, 0x12,
< 0x03, 0x03, 0x10, 0x11, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
---
> 0x0a, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x1a, 0x0a, 0x04,
> 0x54, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x0a, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x74, 0x79,
> 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x4a, 0x70, 0x0a, 0x06, 0x12, 0x04, 0x00, 0x00,
> 0x04, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, 0x00, 0x00, 0x12, 0x0a, 0x0a, 0x0a, 0x02,
> 0x04, 0x00, 0x12, 0x04, 0x02, 0x00, 0x04, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x12,
> 0x03, 0x02, 0x08, 0x0c, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x00, 0x12, 0x03, 0x03, 0x02,
> 0x18, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x04, 0x12, 0x04, 0x03, 0x02, 0x02, 0x0e,
> 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x05, 0x12, 0x03, 0x03, 0x02, 0x08, 0x0a, 0x0c,
> 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x01, 0x12, 0x03, 0x03, 0x09, 0x13, 0x0a, 0x0c, 0x0a, 0x05,
> 0x04, 0x00, 0x02, 0x00, 0x03, 0x12, 0x03, 0x03, 0x16, 0x17, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
> 0x6f, 0x33,