We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Invalid generation of rust code with switch --gen-object-api and struct containing array of size 33 and more.
--gen-object-api
array
33
Generated object api struct implement Default trait by derive macro, but array implement Default trait only for size up to 32 (source).
Default
derive
32
example.fbs
namespace example; struct FooStruct { array_values: [double:81]; } table FooTable { foo_struct: FooStruct; } root_type FooTable;
flatc.exe --rust --gen-object-api example.fbs
#[derive(Debug, Clone, PartialEq, Default)] pub struct FooStructT { pub array_values: [f64; 81], }
flatc - 24.3.25 rustc - 1.82.0
For struct with array implement custom Default trait.
struct
#[derive(Debug, Clone, PartialEq)] pub struct FooStructT { pub array_values: [f64; 81], } impl std::default::Default for FooStructT { fn default() -> Self { Self { array_values: [Default::default(); 81], } } }
The text was updated successfully, but these errors were encountered:
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 C++ developer so it is necessary to review it by some expert.
C++
Sorry, something went wrong.
No branches or pull requests
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: