File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -2884,13 +2884,30 @@ class RustGenerator : public BaseGenerator {
2884
2884
// Generate Struct Object.
2885
2885
if (parser_.opts .generate_object_based_api ) {
2886
2886
// Struct declaration
2887
- code_ += " #[derive(Debug, Clone, PartialEq, Default )]" ;
2887
+ code_ += " #[derive(Debug, Copy, Clone, PartialEq )]" ;
2888
2888
code_ += " {{ACCESS_TYPE}} struct {{STRUCT_OTY}} {" ;
2889
2889
ForAllStructFields (struct_def, [&](const FieldDef &field) {
2890
2890
(void )field; // unused.
2891
2891
code_ += " pub {{FIELD}}: {{FIELD_OTY}}," ;
2892
2892
});
2893
2893
code_ += " }" ;
2894
+
2895
+ // Struct default trait implementation
2896
+ code_ += " impl std::default::Default for {{STRUCT_OTY}} {" ;
2897
+ code_ += " fn default() -> Self {" ;
2898
+ code_ += " Self {" ;
2899
+ ForAllStructFields (struct_def, [&](const FieldDef &field) {
2900
+ const Type &type = field.value .type ;
2901
+ if (IsArray (type)) {
2902
+ code_ += " {{FIELD}}: [Default::default(); " + NumToString (type.fixed_length ) + " ]," ;
2903
+ } else {
2904
+ code_ += " {{FIELD}}: Default::default()," ;
2905
+ }
2906
+ });
2907
+ code_ += " }" ;
2908
+ code_ += " }" ;
2909
+ code_ += " }" ;
2910
+
2894
2911
// The `pack` method that turns the native struct into its Flatbuffers
2895
2912
// counterpart.
2896
2913
code_ += " impl {{STRUCT_OTY}} {" ;
You can’t perform that action at this time.
0 commit comments