@@ -23,39 +23,32 @@ namespace rust {
2323
2424void SingularString::InMsgImpl (Context& ctx, const FieldDescriptor& field,
2525 AccessorCase accessor_case) const {
26- std::string hazzer_thunk = ThunkName (ctx, field, " has" );
27- std::string getter_thunk = ThunkName (ctx, field, " get" );
28- std::string setter_thunk = ThunkName (ctx, field, " set" );
29- std::string proxied_type = RsTypePath (ctx, field);
30-
31- auto transform_view = [&] {
32- if (field.type () == FieldDescriptor::TYPE_STRING) {
33- ctx.Emit (R"rs(
34- // SAFETY: The runtime doesn't require ProtoStr to be UTF-8.
35- unsafe { $pb$::ProtoStr::from_utf8_unchecked(view) }
36- )rs" );
37- } else {
38- ctx.Emit (" view" );
39- }
40- };
4126 ctx.Emit (
4227 {
4328 {" field" , RsSafeName (field.name ())},
44- {" hazzer_thunk" , hazzer_thunk},
45- {" getter_thunk" , getter_thunk},
46- {" setter_thunk" , setter_thunk},
47- {" proxied_type" , proxied_type},
48- {" transform_view" , transform_view},
29+ {" hazzer_thunk" , ThunkName (ctx, field, " has" )},
30+ {" getter_thunk" , ThunkName (ctx, field, " get" )},
31+ {" setter_thunk" , ThunkName (ctx, field, " set" )},
32+ {" clearer_thunk" , ThunkName (ctx, field, " clear" )},
33+ {" proxied_type" , RsTypePath (ctx, field)},
34+ {" transform_view" ,
35+ [&] {
36+ if (field.type () == FieldDescriptor::TYPE_STRING) {
37+ ctx.Emit (R"rs(
38+ // SAFETY: The runtime doesn't require ProtoStr to be UTF-8.
39+ unsafe { $pb$::ProtoStr::from_utf8_unchecked(view) }
40+ )rs" );
41+ } else {
42+ ctx.Emit (" view" );
43+ }
44+ }},
4945 {" view_lifetime" , ViewLifetime (accessor_case)},
5046 {" view_self" , ViewReceiver (accessor_case)},
5147 {" field_optional_getter" ,
5248 [&] {
5349 if (!field.is_optional ()) return ;
5450 if (!field.has_presence ()) return ;
55- ctx.Emit ({{" hazzer_thunk" , hazzer_thunk},
56- {" getter_thunk" , getter_thunk},
57- {" transform_view" , transform_view}},
58- R"rs(
51+ ctx.Emit (R"rs(
5952 pub fn $field$_opt($view_self$) -> $pb$::Optional<&$view_lifetime$ $proxied_type$> {
6053 let view = unsafe { $getter_thunk$(self.raw_msg()).as_ref() };
6154 $pb$::Optional::new(
@@ -73,10 +66,7 @@ void SingularString::InMsgImpl(Context& ctx, const FieldDescriptor& field,
7366 if (field.has_presence ()) {
7467 ctx.Emit (
7568 {
76- {" field" , RsSafeName (field.name ())},
77- {" proxied_type" , proxied_type},
7869 {" default_val" , DefaultValue (ctx, field)},
79- {" view_type" , proxied_type},
8070 {" transform_field_entry" ,
8171 [&] {
8272 if (field.type () == FieldDescriptor::TYPE_STRING) {
@@ -89,10 +79,6 @@ void SingularString::InMsgImpl(Context& ctx, const FieldDescriptor& field,
8979 ctx.Emit (" out" );
9080 }
9181 }},
92- {" hazzer_thunk" , hazzer_thunk},
93- {" getter_thunk" , getter_thunk},
94- {" setter_thunk" , setter_thunk},
95- {" clearer_thunk" , ThunkName (ctx, field, " clear" )},
9682 },
9783 R"rs(
9884 pub fn $field$_mut(&mut self) -> $pb$::FieldEntry<'_, $proxied_type$> {
@@ -118,11 +104,7 @@ void SingularString::InMsgImpl(Context& ctx, const FieldDescriptor& field,
118104 }
119105 )rs" );
120106 } else {
121- ctx.Emit ({{" field" , RsSafeName (field.name ())},
122- {" proxied_type" , proxied_type},
123- {" getter_thunk" , getter_thunk},
124- {" setter_thunk" , setter_thunk}},
125- R"rs(
107+ ctx.Emit (R"rs(
126108 pub fn $field$_mut(&mut self) -> $pb$::Mut<'_, $proxied_type$> {
127109 static VTABLE: $pbi$::BytesMutVTable =
128110 $pbi$::BytesMutVTable::new(
0 commit comments