I have a .proto file:
enum AssetAttrAggregationSourceType {
AttrMeasureDacoo = 0;
AttrTask = 1;
AttrMeasurePipeline = 3;
}
message AssetAttrAggregationCreateEvent {
int64 id = 1;
int64 sourceId = 2;
AssetAttrAggregationSourceType sourceType = 3;
optional int64 associationId = 4;
}
/// build.rs
/// prost = "0.13"
/// prost-types = "0.13"
/// prost-build = "0.13"
fn main() {
let mut config = prost_build::Config::new();
config
.out_dir("src/queue/msg")
.compile_protos(&["cluster_event.proto"], &["proto/"])
.unwrap();
}
After using prost-build to generate the code, it looks like this:
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum AssetAttrAggregationSourceType {
AttrMeasureDacoo = 0,
AttrTask = 1,
AttrMeasurePipeline = 3,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AssetAttrAggregationCreateEvent {
#[prost(int64, tag = "1")]
pub id: i64,
#[prost(int64, tag = "2")]
pub source_id: i64,
#[prost(enumeration = "AssetAttrAggregationSourceType", tag = "3")]
pub source_type: i32,
#[prost(int64, optional, tag = "4")]
pub association_id: ::core::option::Option<i64>
}
Why can't we generate AssetAttrAggregationCreateEvent like the following (Oneof is fine, but it's inconvenient to use now, and we need to convert From every time):
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct AssetAttrAggregationCreateEvent {
#[prost(int64, tag = "1")]
pub id: i64,
#[prost(int64, tag = "2")]
pub source_id: i64,
#[prost(enumeration = "AssetAttrAggregationSourceType", tag = "3")]
pub source_type: AssetAttrAggregationSourceType,
#[prost(int64, optional, tag = "4")]
pub association_id: ::core::option::Option<i64>
}
I have a
.protofile:After using
prost-buildto generate the code, it looks like this:Why can't we generate
AssetAttrAggregationCreateEventlike the following (Oneofis fine, but it's inconvenient to use now, and we need to convertFromevery time):