diff --git a/resources/scalars.json b/resources/scalars.json index 17ffe9d1..5f2d8308 100644 --- a/resources/scalars.json +++ b/resources/scalars.json @@ -3,6 +3,7 @@ "protoType": "double", "notes": "", "cppType": "double", + "rustType": "f64", "csType": "double", "goType": "float64", "javaType": "double", @@ -14,6 +15,7 @@ "protoType": "float", "notes": "", "cppType": "float", + "rustType": "f32", "csType": "float", "goType": "float32", "javaType": "float", @@ -25,6 +27,7 @@ "protoType": "int32", "notes": "Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead.", "cppType": "int32", + "rustType": "i32", "csType": "int", "goType": "int32", "javaType": "int", @@ -36,6 +39,7 @@ "protoType": "int64", "notes": "Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead.", "cppType": "int64", + "rustType": "i64", "csType": "long", "goType": "int64", "javaType": "long", @@ -47,6 +51,7 @@ "protoType": "uint32", "notes": "Uses variable-length encoding.", "cppType": "uint32", + "rustType": "u32", "csType": "uint", "goType": "uint32", "javaType": "int", @@ -58,6 +63,7 @@ "protoType": "uint64", "notes": "Uses variable-length encoding.", "cppType": "uint64", + "rustType": "u64", "csType": "ulong", "goType": "uint64", "javaType": "long", @@ -69,6 +75,7 @@ "protoType": "sint32", "notes": "Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s.", "cppType": "int32", + "rustType": "i32", "csType": "int", "goType": "int32", "javaType": "int", @@ -80,6 +87,7 @@ "protoType": "sint64", "notes": "Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s.", "cppType": "int64", + "rustType": "i64", "csType": "long", "goType": "int64", "javaType": "long", @@ -91,6 +99,7 @@ "protoType": "fixed32", "notes": "Always four bytes. More efficient than uint32 if values are often greater than 2^28.", "cppType": "uint32", + "rustType": "u64", "csType": "uint", "goType": "uint32", "javaType": "int", @@ -102,6 +111,7 @@ "protoType": "fixed64", "notes": "Always eight bytes. More efficient than uint64 if values are often greater than 2^56.", "cppType": "uint64", + "rustType": "u64", "csType": "ulong", "goType": "uint64", "javaType": "long", @@ -113,6 +123,7 @@ "protoType": "sfixed32", "notes": "Always four bytes.", "cppType": "int32", + "rustType": "i32", "csType": "int", "goType": "int32", "javaType": "int", @@ -124,6 +135,7 @@ "protoType": "sfixed64", "notes": "Always eight bytes.", "cppType": "int64", + "rustType": "i64", "csType": "long", "goType": "int64", "javaType": "long", @@ -135,6 +147,7 @@ "protoType": "bool", "notes": "", "cppType": "bool", + "rustType": "bool", "csType": "bool", "goType": "bool", "javaType": "boolean", @@ -146,6 +159,7 @@ "protoType": "string", "notes": "A string must always contain UTF-8 encoded or 7-bit ASCII text.", "cppType": "string", + "rustType": "String", "csType": "string", "goType": "string", "javaType": "String", @@ -157,6 +171,7 @@ "protoType": "bytes", "notes": "May contain any arbitrary sequence of bytes.", "cppType": "string", + "rustType": "Vec", "csType": "ByteString", "goType": "[]byte", "javaType": "ByteString", diff --git a/template.go b/template.go index b8b5224d..4010ca26 100644 --- a/template.go +++ b/template.go @@ -80,7 +80,8 @@ func NewTemplate(descs []*protokit.FileDescriptor) *Template { if valueField.Name != "value" { panic(fmt.Sprintf("expected map entry's first field to be 'value', not '%s'", valueField.Name)) } - typeName := fmt.Sprintf("map<%s, %s>", keyField.Type, valueField.Type) + typeName := fmt.Sprintf("map<%s, %s>", keyField.Type, valueField.Type) + f.Label = "" f.Type = typeName f.FullType = typeName f.LongType = typeName @@ -424,6 +425,7 @@ type ScalarValue struct { Notes string `json:"notes"` CppType string `json:"cppType"` CSharp string `json:"csType"` + RustType string `json:"rustType"` GoType string `json:"goType"` JavaType string `json:"javaType"` PhpType string `json:"phpType"` diff --git a/template_test.go b/template_test.go index 90b5cc16..dd1a7b5c 100644 --- a/template_test.go +++ b/template_test.go @@ -277,10 +277,10 @@ func TestFieldProperties(t *testing.T) { field = findField("properties", findMessage("Vehicle", vehicleFile)) require.Equal(t, "properties", field.Name) - require.Equal(t, "repeated", field.Label) - require.Equal(t, "map", field.Type) - require.Equal(t, "map", field.LongType) - require.Equal(t, "map", field.FullType) + require.Equal(t, "", field.Label) + require.Equal(t, "map<string, string>", field.Type) + require.Equal(t, "map<string, string>", field.LongType) + require.Equal(t, "map<string, string>", field.FullType) require.Empty(t, field.DefaultValue) require.True(t, field.IsMap) require.False(t, field.IsOneof)