Skip to content

Commit 38fab3a

Browse files
authored
feat(types): hide empty _unknown_fields (#2744)
* feat(types): hide empty _unknown_fields * fix style
1 parent 2e8d0b2 commit 38fab3a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

internal/rust/templates/common/message.mustache

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919
{{{.}}}
2020
{{/Codec.DocLines}}
2121
{{> /templates/common/feature_gate}}
22-
#[derive(Clone, Debug, Default, PartialEq)]
22+
#[derive(Clone, Default, PartialEq)]
2323
#[non_exhaustive]
2424
{{#Deprecated}}
2525
#[deprecated]
@@ -338,6 +338,24 @@ impl serde::ser::Serialize for {{Codec.Name}} {
338338
state.end()
339339
}
340340
}
341+
342+
{{> /templates/common/feature_gate}}
343+
impl std::fmt::Debug for {{Codec.Name}} {
344+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
345+
let mut debug_struct = f.debug_struct("{{Codec.Name}}");
346+
{{#Codec.BasicFields}}
347+
debug_struct.field("{{Codec.FieldName}}", &self.{{Codec.FieldName}});
348+
{{/Codec.BasicFields}}
349+
{{#OneOfs}}
350+
debug_struct.field("{{Codec.FieldName}}", &self.{{Codec.FieldName}});
351+
{{/OneOfs}}
352+
353+
if !self._unknown_fields.is_empty() {
354+
debug_struct.field("_unknown_fields", &self._unknown_fields);
355+
}
356+
debug_struct.finish()
357+
}
358+
}
341359
{{#Codec.HasNestedTypes}}
342360
343361
/// Defines additional types related to [{{Name}}].

0 commit comments

Comments
 (0)