-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Rust default for array #8436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For correction should be sufficient to replace this code: flatbuffers/src/idl_gen_rust.cpp Lines 2910 to 2917 in 595bf00
by this code: // Struct declaration
code_ += "#[derive(Debug, Copy, Clone, PartialEq)]";
code_ += "{{ACCESS_TYPE}} struct {{STRUCT_OTY}} {";
ForAllStructFields(struct_def, [&](const FieldDef &field) {
(void)field; // unused.
code_ += "pub {{FIELD}}: {{FIELD_OTY}},";
});
code_ += "}";
// Struct default trait implementation
code_ += "impl std::default::Default for {{STRUCT_OTY}} {";
code_ += " fn default() -> Self {";
code_ += " Self {";
ForAllStructFields(struct_def, [&](const FieldDef &field) {
const Type &type = field.value.type;
if (IsArray(type)) {
code_ += " {{FIELD}}: [Default::default(); " + NumToString(type.fixed_length) + "],";
} else {
code_ += " {{FIELD}}: Default::default(),";
}
});
code_ += " }";
code_ += " }";
code_ += "}"; Base on some tests everything looks good but I am not |
This issue is stale because it has been open 6 months with no activity. Please comment or label |
This PR should solve this issue. |
Uh oh!
There was an error while loading. Please reload this page.
Issue
Invalid generation of rust code with switch
--gen-object-api
and struct containingarray
of size33
and more.Reason
Generated object api struct implement
Default
trait byderive
macro, butarray
implementDefault
trait only for size up to32
(source).Example of invalid fbs
Fbs file
example.fbs
Command
flatc.exe --rust --gen-object-api example.fbs
Invalid code section
Tool versions
flatc - 24.3.25
rustc - 1.82.0
Potential solution
For
struct
witharray
implement customDefault
trait.Example of solution from code above
The text was updated successfully, but these errors were encountered: