Skip to content

Commit fe1c1be

Browse files
committed
feat(generator/rust): use F32 formatter
1 parent 5a74b29 commit fe1c1be

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

generator/internal/rust/annotate_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ func TestOneOfAnnotations(t *testing.T) {
473473
BranchName: "OneofFieldMap",
474474
FQMessageName: "crate::model::Message",
475475
DocLines: nil,
476-
Attributes: []string{`#[serde_as(as = "std::collections::HashMap<_, wkt::internal::F32>")]`},
476+
Attributes: []string{`#[serde_as(as = "std::collections::HashMap<wkt::internal::I32, wkt::internal::F32>")]`},
477477
FieldType: "std::collections::HashMap<i32,f32>",
478478
PrimitiveFieldType: "std::collections::HashMap<i32,f32>",
479479
AddQueryParameter: `let builder = req.oneof_field_map().map(|p| serde_json::to_value(p).map_err(Error::serde) ).transpose()?.into_iter().fold(builder, |builder, p| { use gaxi::query_parameter::QueryParameter; p.add(builder, "oneofFieldMap") });`,
@@ -818,6 +818,7 @@ func TestJsonNameAnnotations(t *testing.T) {
818818
DocLines: nil,
819819
Attributes: []string{
820820
`#[serde(skip_serializing_if = "wkt::internal::is_default")]`,
821+
`#[serde_as(as = "wkt::internal::I32")]`,
821822
},
822823
FieldType: "i32",
823824
PrimitiveFieldType: "i32",
@@ -836,6 +837,7 @@ func TestJsonNameAnnotations(t *testing.T) {
836837
DocLines: nil,
837838
Attributes: []string{
838839
`#[serde(skip_serializing_if = "std::option::Option::is_none")]`,
840+
`#[serde_as(as = "std::option::Option<wkt::internal::I32>")]`,
839841
},
840842
FieldType: "std::option::Option<i32>",
841843
PrimitiveFieldType: "i32",
@@ -854,6 +856,7 @@ func TestJsonNameAnnotations(t *testing.T) {
854856
DocLines: nil,
855857
Attributes: []string{
856858
`#[serde(skip_serializing_if = "std::vec::Vec::is_empty")]`,
859+
`#[serde_as(as = "std::vec::Vec<wkt::internal::I32>")]`,
857860
},
858861
FieldType: "std::vec::Vec<i32>",
859862
PrimitiveFieldType: "i32",
@@ -1046,7 +1049,7 @@ func TestFieldAnnotations(t *testing.T) {
10461049
FQMessageName: "crate::model::TestMessage",
10471050
Attributes: []string{
10481051
`#[serde(skip_serializing_if = "std::collections::HashMap::is_empty")]`,
1049-
`#[serde_as(as = "std::collections::HashMap<_, serde_with::DisplayFromStr>")]`,
1052+
`#[serde_as(as = "std::collections::HashMap<wkt::internal::I32, serde_with::DisplayFromStr>")]`,
10501053
},
10511054
FieldType: "std::collections::HashMap<i32,i64>",
10521055
PrimitiveFieldType: "std::collections::HashMap<i32,i64>",

generator/internal/rust/codec.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ func fieldFormatter(typez api.Typez) string {
411411
api.SFIXED64_TYPE,
412412
api.SINT64_TYPE:
413413
return "serde_with::DisplayFromStr"
414+
case api.INT32_TYPE, api.SINT32_TYPE, api.SFIXED32_TYPE:
415+
return "wkt::internal::I32"
414416
case api.FLOAT_TYPE:
415417
return "wkt::internal::F32"
416418
case api.DOUBLE_TYPE:
@@ -476,6 +478,10 @@ func wrapperFieldAttributes(f *api.Field, attributes []string) []string {
476478
formatter = fieldFormatter(api.UINT64_TYPE)
477479
case ".google.protobuf.Int64Value":
478480
formatter = fieldFormatter(api.INT64_TYPE)
481+
case ".google.protobuf.UInt32Value":
482+
formatter = fieldFormatter(api.UINT32_TYPE)
483+
case ".google.protobuf.Int32Value":
484+
formatter = fieldFormatter(api.INT32_TYPE)
479485
case ".google.protobuf.FloatValue":
480486
formatter = fieldFormatter(api.FLOAT_TYPE)
481487
case ".google.protobuf.DoubleValue":
@@ -524,18 +530,18 @@ func fieldAttributes(f *api.Field, state *api.APIState) []string {
524530
}
525531
attributes := fieldBaseAttributes(f)
526532
switch f.Typez {
527-
case api.INT32_TYPE,
528-
api.FIXED32_TYPE,
533+
case api.FIXED32_TYPE,
529534
api.BOOL_TYPE,
530535
api.STRING_TYPE,
531536
api.UINT32_TYPE,
532-
api.SFIXED32_TYPE,
533-
api.SINT32_TYPE,
534537
api.ENUM_TYPE,
535538
api.GROUP_TYPE:
536539
return append(attributes, fieldSkipAttributes(f)...)
537540

538-
case api.INT64_TYPE,
541+
case api.INT32_TYPE,
542+
api.SFIXED32_TYPE,
543+
api.SINT32_TYPE,
544+
api.INT64_TYPE,
539545
api.UINT64_TYPE,
540546
api.FIXED64_TYPE,
541547
api.SFIXED64_TYPE,

0 commit comments

Comments
 (0)