Rules for translating a Rust structure to a Protobuf structure 〚—〛 |
$T |
〚$T〛 |
Comments |
enum $T {
Var1(...),
Var2(...),
}
|
message Proto$T {
oneof kind {
〚$Var1〛 var_1 = 1;
〚$Var2〛 var_2 = 2;
}
}
|
The variant types 〚$VarX〛 are determined by the structure of the variant. |
struct $V3;
struct $V4();
enum $T {
Var1,
Var2(),
Var3($V3),
Var4($V4),
}
|
message Proto$T {
oneof kind {
google.protobuf.Empty var_1 = 1;
google.protobuf.Empty var_2 = 2;
google.protobuf.Empty var_3 = 3;
google.protobuf.Empty var_4 = 4;
}
}
|
Nullary variants or unary variants of a nullary type have the Empty Protobuf type. |
enum $T {
Var1(usize),
}
|
message Proto$T {
oneof kind {
uint64 var_1 = 1;
}
}
|
Use the corresponding protobuf primitive type for Rust primitive types that have a Protobuf counterpart. |
enum $T {
Var1(u64),
}
|
message Proto$T {
oneof kind {
uint64 var_1 = 1;
}
}
|
Use the Protobuf representation type for Rust primitive types that implement ProtoRepr . |
enum $T {
Var1($V1),
}
|
message Proto$T {
oneof kind {
Proto$V1 var_1 = 1;
}
}
|
Use Proto$V1 if $Var1 is a complex variant for which Proto$V1 already exists. |
struct $V1($U1);
enum $T {
Var1($V1),
}
|
message Proto$T {
oneof kind {
〚$U1〛 var_1 = 1;
}
}
|
Use the type that corresponds to $U1 for a unary variant of a unary struct. If $U1 is Optional<_> , use the complex variant case (see the next item in the table). |
enum $T {
Var1 { .. },
}
|
message Proto$T {
message Proto$Var1 { 〚..〛 }
oneof kind {
Proto$Var1 var_1 = 1;
}
}
|
For complex variants, create a nested message type. |
struct $T {
f1 : Option<$F1>,
}
|
message Proto$T {
Proto$F1 f1 = 1;
}
|
If $F1 is a complex type. |
struct $T {
f1 : Option<$F1>,
}
|
message Proto$T {
optional Proto$F1 f1 = 1;
}
|
If 〚$F1〛 is a primitive Protobuf type. |
HashMap<$K, $V>
BTreeMap<$K, $V>
|
map<〚$K〛, 〚$V〛>
|
If 〚$K〛 is a primitive Protobuf type. |
HashMap<$K, $V>
BTreeMap<$K, $V>
|
repeated 〚($K, $V)〛
|
If 〚$K〛 is not a primitive Protobuf type. |
struct $T {
f1 : vec<$V>
}
|
message Proto$T {
repeated Proto$V f1 = 1;
}
|
Represent a 1-dimensional $V vector as a repeated field of the translated item type Proto$V . |
struct $T {
f1 : vec<vec<$T1>>
}
|
message Proto$V { … }
message Proto${V}Vec {
repeated Proto$V value = 1;
}
message Proto$V {
repeated Proto${V}Vec f1 = 1;
}
|
Represent a 2-dimensional $V vector as a repeated field of type Proto${V}Vec , where the latter is a dedicated struct that represents a 1-dimensional $V vector. |
|
|
|