From 17581113f86c536e48b497a9e8882c6df2b0e763 Mon Sep 17 00:00:00 2001 From: pittengermdp Date: Thu, 19 Feb 2026 08:09:22 -0600 Subject: [PATCH 1/3] [Rust] Improve Object API codegen: idiomatic types, Eq/Hash derives, String shadowing fix - Use short type names (String, Vec, Box) instead of fully-qualified alloc:: paths in generated Object API code. Add corresponding `use alloc::{vec::Vec, string::String, boxed::Box, string::ToString}` imports to maintain no_std compatibility. - Derive Eq and Hash on Object API types (tables, structs, unions, bitflags) when the type hierarchy contains no floating-point fields. Types with f32/f64 fields continue to derive only PartialEq. - Fix String type shadowing: when a schema defines a table named "String" in the same namespace, generated code now emits std::string::String for standard library string fields, preventing compilation failures. Wires up the existing but unused NamespaceShadowsString/ObjectStringType helpers. - Add #[allow(unused_imports)] to generated use/crate imports to suppress warnings when not all imported names are used. - Fix serde Deserialize impl for enums to use fully-qualified std::string::String to avoid shadowing conflicts. Regenerated all test files via scripts/generate_code.py. --- .../my_game/sample/color_generated.rs | 4 + .../my_game/sample/equipment_generated.rs | 11 +- .../my_game/sample/monster_generated.rs | 21 +-- .../my_game/sample/vec_3_generated.rs | 4 + .../my_game/sample/weapon_generated.rs | 11 +- src/idl_gen_rust.cpp | 152 +++++++++++++++--- .../my_game/example/array_struct_generated.rs | 4 + .../my_game/example/array_table_generated.rs | 5 +- .../example/nested_struct_generated.rs | 6 +- .../my_game/example/test_enum_generated.rs | 4 + .../from_include_generated.rs | 4 + .../other_name_space/table_b_generated.rs | 11 +- .../other_name_space/unused_generated.rs | 6 +- tests/include_test1/table_a_generated.rs | 11 +- tests/include_test1_generated.rs | 28 ++-- .../from_include_generated.rs | 4 + .../other_name_space/table_b_generated.rs | 11 +- .../other_name_space/unused_generated.rs | 6 +- tests/include_test2/table_a_generated.rs | 11 +- tests/include_test2_generated.rs | 28 ++-- .../keyword_test/abc_generated.rs | 4 + .../keywords_in_table_generated.rs | 7 +- .../keywords_in_union_generated.rs | 15 +- .../keyword_test/public_generated.rs | 4 + .../keyword_test/table_2_generated.rs | 11 +- .../my_game/example/ability_generated.rs | 6 +- .../any_ambiguous_aliases_generated.rs | 17 +- .../my_game/example/any_generated.rs | 17 +- .../example/any_unique_aliases_generated.rs | 17 +- .../my_game/example/color_generated.rs | 6 +- .../my_game/example/long_enum_generated.rs | 6 +- .../my_game/example/monster_generated.rs | 103 ++++++------ .../my_game/example/race_generated.rs | 4 + .../my_game/example/referrable_generated.rs | 7 +- .../my_game/example/stat_generated.rs | 11 +- .../example/struct_of_structs_generated.rs | 6 +- .../struct_of_structs_of_structs_generated.rs | 6 +- .../my_game/example/test_generated.rs | 6 +- .../test_simple_table_with_enum_generated.rs | 7 +- .../my_game/example/type_aliases_generated.rs | 9 +- .../my_game/example/vec_3_generated.rs | 4 + .../my_game/example_2/monster_generated.rs | 7 +- .../my_game/in_parent_namespace_generated.rs | 7 +- .../from_include_generated.rs | 4 + .../other_name_space/table_b_generated.rs | 11 +- .../other_name_space/unused_generated.rs | 6 +- tests/monster_test/table_a_generated.rs | 11 +- .../my_game/example/ability_generated.rs | 6 +- .../any_ambiguous_aliases_generated.rs | 19 ++- .../my_game/example/any_generated.rs | 19 ++- .../example/any_unique_aliases_generated.rs | 19 ++- .../my_game/example/color_generated.rs | 6 +- .../my_game/example/long_enum_generated.rs | 6 +- .../my_game/example/monster_generated.rs | 103 ++++++------ .../my_game/example/race_generated.rs | 6 +- .../my_game/example/referrable_generated.rs | 7 +- .../my_game/example/stat_generated.rs | 11 +- .../example/struct_of_structs_generated.rs | 6 +- .../struct_of_structs_of_structs_generated.rs | 6 +- .../my_game/example/test_generated.rs | 6 +- .../test_simple_table_with_enum_generated.rs | 7 +- .../my_game/example/type_aliases_generated.rs | 9 +- .../my_game/example/vec_3_generated.rs | 4 + .../my_game/example_2/monster_generated.rs | 7 +- .../my_game/in_parent_namespace_generated.rs | 7 +- .../from_include_generated.rs | 6 +- .../other_name_space/table_b_generated.rs | 11 +- .../other_name_space/unused_generated.rs | 6 +- .../table_a_generated.rs | 11 +- tests/monsterdata_python_wire.mon | Bin 344 -> 344 bytes tests/more_defaults/abc_generated.rs | 4 + .../more_defaults/more_defaults_generated.rs | 25 +-- .../enum_in_nested_ns_generated.rs | 4 + .../struct_in_nested_ns_generated.rs | 6 +- .../table_in_nested_ns_generated.rs | 7 +- .../union_in_nested_ns_generated.rs | 11 +- .../second_table_in_a_generated.rs | 11 +- .../table_in_first_ns_generated.rs | 13 +- .../namespace_c/table_in_c_generated.rs | 15 +- .../optional_byte_generated.rs | 4 + .../scalar_stuff_generated.rs | 5 +- tests/private_annotation_test/ab_generated.rs | 4 + .../annotations_generated.rs | 7 +- .../private_annotation_test/any_generated.rs | 15 +- .../private_annotation_test/game_generated.rs | 7 +- .../object_generated.rs | 6 +- .../rust_namer_test/field_table_generated.rs | 7 +- .../rust_namer_test/field_union_generated.rs | 11 +- .../rust_namer_test/game_message_generated.rs | 19 ++- .../game_message_wrapper_generated.rs | 13 +- .../player_input_change_generated.rs | 7 +- .../player_spectate_generated.rs | 7 +- .../player_stat_event_generated.rs | 7 +- .../possibly_reserved_words_generated.rs | 4 + .../rust_namer_test/root_table_generated.rs | 9 +- tests/service_test_generated.py | 17 +- 96 files changed, 813 insertions(+), 381 deletions(-) diff --git a/samples/rust_generated/my_game/sample/color_generated.rs b/samples/rust_generated/my_game/sample/color_generated.rs index 34b82ac7b12..38de74b4e87 100644 --- a/samples/rust_generated/my_game/sample/color_generated.rs +++ b/samples/rust_generated/my_game/sample/color_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_COLOR: i8 = 0; diff --git a/samples/rust_generated/my_game/sample/equipment_generated.rs b/samples/rust_generated/my_game/sample/equipment_generated.rs index f53f8f20b05..cbb7d54f192 100644 --- a/samples/rust_generated/my_game/sample/equipment_generated.rs +++ b/samples/rust_generated/my_game/sample/equipment_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_EQUIPMENT: u8 = 0; @@ -89,11 +93,10 @@ impl ::flatbuffers::SimpleToVerifyInSlice for Equipment {} pub struct EquipmentUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum EquipmentT { NONE, - Weapon(alloc::boxed::Box), + Weapon(Box), } impl Default for EquipmentT { fn default() -> Self { @@ -114,7 +117,7 @@ impl EquipmentT { } } /// If the union variant matches, return the owned WeaponT, setting the union to NONE. - pub fn take_weapon(&mut self) -> Option> { + pub fn take_weapon(&mut self) -> Option> { if let Self::Weapon(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::Weapon(w) = v { diff --git a/samples/rust_generated/my_game/sample/monster_generated.rs b/samples/rust_generated/my_game/sample/monster_generated.rs index 381091dd721..58dbc4f94c5 100644 --- a/samples/rust_generated/my_game/sample/monster_generated.rs +++ b/samples/rust_generated/my_game/sample/monster_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum MonsterOffset {} #[derive(Copy, Clone, PartialEq)] @@ -63,7 +67,7 @@ impl<'a> Monster<'a> { let mana = self.mana(); let hp = self.hp(); let name = self.name().map(|x| { - alloc::string::ToString::to_string(x) + x.to_string() }); let inventory = self.inventory().map(|x| { x.into_iter().collect() @@ -74,7 +78,7 @@ impl<'a> Monster<'a> { }); let equipped = match self.equipped_type() { Equipment::NONE => EquipmentT::NONE, - Equipment::Weapon => EquipmentT::Weapon(alloc::boxed::Box::new( + Equipment::Weapon => EquipmentT::Weapon(Box::new( self.equipped_as_weapon() .expect("Invalid union table, expected `Equipment::Weapon`.") .unpack() @@ -326,18 +330,17 @@ impl ::core::fmt::Debug for Monster<'_> { ds.finish() } } -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MonsterT { pub pos: Option, pub mana: i16, pub hp: i16, - pub name: Option, - pub inventory: Option>, + pub name: Option, + pub inventory: Option>, pub color: Color, - pub weapons: Option>, + pub weapons: Option>, pub equipped: EquipmentT, - pub path: Option>, + pub path: Option>, } impl Default for MonsterT { fn default() -> Self { @@ -371,12 +374,12 @@ impl MonsterT { }); let color = self.color; let weapons = self.weapons.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) }); let equipped_type = self.equipped.equipment_type(); let equipped = self.equipped.pack(_fbb); let path = self.path.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) }); Monster::create(_fbb, &MonsterArgs{ pos, diff --git a/samples/rust_generated/my_game/sample/vec_3_generated.rs b/samples/rust_generated/my_game/sample/vec_3_generated.rs index 51624680279..b82aaf0bf2a 100644 --- a/samples/rust_generated/my_game/sample/vec_3_generated.rs +++ b/samples/rust_generated/my_game/sample/vec_3_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct Vec3, aligned to 4 #[repr(transparent)] diff --git a/samples/rust_generated/my_game/sample/weapon_generated.rs b/samples/rust_generated/my_game/sample/weapon_generated.rs index 7a4c2e79a7a..27a90d84307 100644 --- a/samples/rust_generated/my_game/sample/weapon_generated.rs +++ b/samples/rust_generated/my_game/sample/weapon_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum WeaponOffset {} #[derive(Copy, Clone, PartialEq)] @@ -42,7 +46,7 @@ impl<'a> Weapon<'a> { pub fn unpack(&self) -> WeaponT { let name = self.name().map(|x| { - alloc::string::ToString::to_string(x) + x.to_string() }); let damage = self.damage(); WeaponT { @@ -129,10 +133,9 @@ impl ::core::fmt::Debug for Weapon<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct WeaponT { - pub name: Option, + pub name: Option, pub damage: i16, } impl Default for WeaponT { diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index b7a565d00cd..05cf3319037 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -375,6 +375,12 @@ class RustGenerator : public BaseGenerator { code_ += "// " + std::string(FlatBuffersGeneratedWarning()); code_ += "// @generated"; code_ += "extern crate alloc;"; + if (parser_.opts.generate_object_based_api) { + code_ += "use alloc::vec::Vec;"; + code_ += "use alloc::string::String;"; + code_ += "use alloc::boxed::Box;"; + code_ += "use alloc::string::ToString;"; + } if (parser_.opts.rust_serialize) { code_ += "extern crate serde;"; code_ += @@ -730,7 +736,7 @@ class RustGenerator : public BaseGenerator { code_ += "mod bitflags_{{ENUM_NAMESPACE}} {"; code_ += " ::flatbuffers::bitflags::bitflags! {"; GenComment(enum_def.doc_comment, " "); - code_ += " #[derive(Default, Debug, Clone, Copy, PartialEq)]"; + code_ += " #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]"; code_ += " {{ACCESS_TYPE}} struct {{ENUM_TY}}: {{BASE_TYPE}} {"; ForAllEnumValues1(enum_def, [&](const EnumVal& ev) { this->GenComment(ev.doc_comment, " "); @@ -844,7 +850,7 @@ class RustGenerator : public BaseGenerator { code_ += " where"; code_ += " D: serde::Deserializer<'de>,"; code_ += " {"; - code_ += " let s = String::deserialize(deserializer)?;"; + code_ += " let s = ::deserialize(deserializer)?;"; code_ += " for item in {{ENUM_TY}}::ENUM_VALUES {"; code_ += " if let Some(item_name) = item.variant_name() {"; code_ += " if item_name == s {"; @@ -957,13 +963,12 @@ class RustGenerator : public BaseGenerator { // Generate native union. code_ += "#[allow(clippy::upper_case_acronyms)]"; // NONE's spelling is // intended. - code_ += "#[non_exhaustive]"; - code_ += "#[derive(Debug, Clone, PartialEq)]"; + code_ += ObjectDerives(UnionIsHashable(enum_def)); code_ += "{{ACCESS_TYPE}} enum {{ENUM_OTY}} {"; code_ += " NONE,"; ForAllUnionObjectVariantsBesidesNone(enum_def, [&] { code_ += - "{{NATIVE_VARIANT}}(alloc::boxed::Box<{{U_ELEMENT_TABLE_TYPE}}>),"; + "{{NATIVE_VARIANT}}(Box<{{U_ELEMENT_TABLE_TYPE}}>),"; }); code_ += "}"; // Generate Default (NONE). @@ -1011,7 +1016,7 @@ class RustGenerator : public BaseGenerator { "{{U_ELEMENT_TABLE_TYPE}}, setting the union to NONE."; code_ += "pub fn take_{{U_ELEMENT_NAME}}(&mut self) -> " - "Option> {"; + "Option> {"; code_ += " if let Self::{{NATIVE_VARIANT}}(_) = self {"; code_ += " let v = ::core::mem::replace(self, Self::NONE);"; code_ += " if let Self::{{NATIVE_VARIANT}}(w) = v {"; @@ -1105,7 +1110,7 @@ class RustGenerator : public BaseGenerator { const std::string defval = field.IsRequired() ? "\"\"" : "\"" + field.value.constant + "\""; if (context == kObject) { - return "alloc::string::ToString::to_string(" + defval + ")"; + return defval + ".to_string()"; } if (context == kAccessor) return "&" + defval; FLATBUFFERS_ASSERT(false); @@ -1224,7 +1229,8 @@ class RustGenerator : public BaseGenerator { return "INVALID_CODE_GENERATION"; // for return analysis } - std::string ObjectFieldType(const FieldDef& field, bool in_a_table) { + std::string ObjectFieldType(const FieldDef& field, bool in_a_table, + const StructDef* parent_struct = nullptr) { const Type& type = field.value.type; std::string ty; switch (GetFullType(type)) { @@ -1235,7 +1241,7 @@ class RustGenerator : public BaseGenerator { break; } case ftString: { - ty = "alloc::string::String"; + ty = parent_struct ? ObjectStringType(*parent_struct) : "String"; break; } case ftStruct: { @@ -1246,7 +1252,7 @@ class RustGenerator : public BaseGenerator { // Since Tables can contain themselves, Box is required to avoid // infinite types. ty = - "alloc::boxed::Box<" + NamespacedNativeName(*type.struct_def) + ">"; + "Box<" + NamespacedNativeName(*type.struct_def) + ">"; break; } case ftUnionKey: { @@ -1264,24 +1270,24 @@ class RustGenerator : public BaseGenerator { } // Vectors are in tables and are optional case ftVectorOfEnumKey: { - ty = "alloc::vec::Vec<" + WrapInNameSpace(*type.VectorType().enum_def) + + ty = "Vec<" + WrapInNameSpace(*type.VectorType().enum_def) + ">"; break; } case ftVectorOfInteger: case ftVectorOfBool: case ftVectorOfFloat: { - ty = "alloc::vec::Vec<" + GetTypeBasic(type.VectorType()) + ">"; + ty = "Vec<" + GetTypeBasic(type.VectorType()) + ">"; break; } case ftVectorOfString: { - ty = "alloc::vec::Vec"; + ty = "Vec<" + (parent_struct ? ObjectStringType(*parent_struct) : std::string("String")) + ">"; break; } case ftVectorOfTable: case ftVectorOfStruct: { ty = NamespacedNativeName(*type.VectorType().struct_def); - ty = "alloc::vec::Vec<" + ty + ">"; + ty = "Vec<" + ty + ">"; break; } case ftVectorOfUnionValue: { @@ -1789,7 +1795,7 @@ class RustGenerator : public BaseGenerator { ForAllUnionObjectVariantsBesidesNone(enum_def, [&] { code_ += " {{ENUM_TY}}::{{VARIANT_NAME}} => " - "{{NATIVE_ENUM_NAME}}::{{NATIVE_VARIANT}}(alloc::boxed::Box::" + "{{NATIVE_ENUM_NAME}}::{{NATIVE_VARIANT}}(Box::" "new("; code_ += " self.{{FIELD}}_as_{{U_ELEMENT_NAME}}()"; code_ += @@ -1806,7 +1812,7 @@ class RustGenerator : public BaseGenerator { // The rest of the types need special handling based on if the field // is optional or not. case ftString: { - code_.SetValue("EXPR", "alloc::string::ToString::to_string(x)"); + code_.SetValue("EXPR", "x.to_string()"); break; } case ftStruct: { @@ -1814,7 +1820,7 @@ class RustGenerator : public BaseGenerator { break; } case ftTable: { - code_.SetValue("EXPR", "alloc::boxed::Box::new(x.unpack())"); + code_.SetValue("EXPR", "Box::new(x.unpack())"); break; } case ftVectorOfInteger: @@ -1827,7 +1833,7 @@ class RustGenerator : public BaseGenerator { case ftVectorOfString: { code_.SetValue("EXPR", "x.iter().map(|s| " - "alloc::string::ToString::to_string(s)).collect()"); + "s.to_string()).collect()"); break; } case ftVectorOfStruct: @@ -2262,8 +2268,7 @@ class RustGenerator : public BaseGenerator { code_.SetValue("STRUCT_TY", namer_.Type(table)); // Generate the native object. - code_ += "#[non_exhaustive]"; - code_ += "#[derive(Debug, Clone, PartialEq)]"; + code_ += ObjectDerives(TypeIsHashable(table)); code_ += "{{ACCESS_TYPE}} struct {{STRUCT_OTY}} {"; ForAllObjectTableFields(table, [&](const FieldDef& field) { // Union objects combine both the union discriminant and value, so we @@ -2351,7 +2356,7 @@ class RustGenerator : public BaseGenerator { } case ftVectorOfStruct: { MapNativeTableField(field, - "let w: alloc::vec::Vec<_> = x.iter().map(|t| " + "let w: Vec<_> = x.iter().map(|t| " "t.pack()).collect();" "_fbb.create_vector(&w)"); return; @@ -2361,14 +2366,14 @@ class RustGenerator : public BaseGenerator { // allocations. MapNativeTableField(field, - "let w: alloc::vec::Vec<_> = x.iter().map(|s| " + "let w: Vec<_> = x.iter().map(|s| " "_fbb.create_string(s)).collect();" "_fbb.create_vector(&w)"); return; } case ftVectorOfTable: { MapNativeTableField(field, - "let w: alloc::vec::Vec<_> = x.iter().map(|t| " + "let w: Vec<_> = x.iter().map(|t| " "t.pack(_fbb)).collect();" "_fbb.create_vector(&w)"); return; @@ -2401,7 +2406,7 @@ class RustGenerator : public BaseGenerator { const FieldDef& field = **it; if (field.deprecated) continue; code_.SetValue("FIELD", namer_.Field(field)); - code_.SetValue("FIELD_OTY", ObjectFieldType(field, true)); + code_.SetValue("FIELD_OTY", ObjectFieldType(field, true, &table)); code_.IncrementIdentLevel(); cb(field); code_.DecrementIdentLevel(); @@ -2637,7 +2642,7 @@ class RustGenerator : public BaseGenerator { it != struct_def.fields.vec.end(); ++it) { const auto& field = **it; code_.SetValue("FIELD_TYPE", GetTypeGet(field.value.type)); - code_.SetValue("FIELD_OTY", ObjectFieldType(field, false)); + code_.SetValue("FIELD_OTY", ObjectFieldType(field, false, &struct_def)); code_.SetValue("FIELD", namer_.Field(field)); code_.SetValue("FIELD_OFFSET", NumToString(offset_to_field)); code_.SetValue( @@ -2939,7 +2944,14 @@ class RustGenerator : public BaseGenerator { // Generate Struct Object. if (parser_.opts.generate_object_based_api) { // Struct declaration - code_ += "#[derive(Debug, Clone, PartialEq, Default)]"; + { + std::string derives = "#[derive(Debug, Clone, PartialEq, Default"; + if (TypeIsHashable(struct_def)) { + derives += ", Eq, Hash"; + } + derives += ")]"; + code_ += derives; + } code_ += "{{ACCESS_TYPE}} struct {{STRUCT_OTY}} {"; ForAllStructFields(struct_def, [&](const FieldDef& field) { (void)field; // unused. @@ -2987,12 +2999,14 @@ class RustGenerator : public BaseGenerator { auto basename = flatbuffers::StripPath(noext); if (parser_.opts.include_prefix.empty()) { + code_ += indent + "#[allow(unused_imports)]"; code_ += indent + "use crate::" + basename + parser_.opts.filename_suffix + "::*;"; } else { auto prefix = parser_.opts.include_prefix; prefix.pop_back(); + code_ += indent + "#[allow(unused_imports)]"; code_ += indent + "use crate::" + prefix + "::" + basename + parser_.opts.filename_suffix + "::*;"; } @@ -3000,12 +3014,19 @@ class RustGenerator : public BaseGenerator { } if (parser_.opts.rust_serialize) { code_ += indent + "extern crate serde;"; + code_ += indent + "#[allow(unused_imports)]"; code_ += indent + "use self::serde::ser::{Serialize, Serializer, SerializeStruct};"; code_ += ""; } code_ += "extern crate alloc;"; + if (parser_.opts.generate_object_based_api) { + code_ += "use alloc::vec::Vec;"; + code_ += "use alloc::string::String;"; + code_ += "use alloc::boxed::Box;"; + code_ += "use alloc::string::ToString;"; + } } // Set up the correct namespace. This opens a namespace if the current @@ -3057,6 +3078,85 @@ class RustGenerator : public BaseGenerator { cur_name_space_ = ns; } + // Check if a type transitively contains f32/f64 fields. + // Types with floats cannot derive Hash or Eq. + bool HasFloatFields(const StructDef& struct_def, + std::set& visited) const { + if (!visited.insert(&struct_def).second) return false; + for (auto it = struct_def.fields.vec.begin(); + it != struct_def.fields.vec.end(); ++it) { + const FieldDef& field = **it; + if (IsFloat(field.value.type.base_type)) return true; + // Check vector element type + if (IsVector(field.value.type) && + IsFloat(field.value.type.VectorType().base_type)) + return true; + // Check nested struct/table + if (field.value.type.struct_def && + HasFloatFields(*field.value.type.struct_def, visited)) + return true; + // Check union variants + if (field.value.type.enum_def && + HasFloatFieldsInUnion(*field.value.type.enum_def, visited)) + return true; + } + return false; + } + + bool HasFloatFieldsInUnion(const EnumDef& enum_def, + std::set& visited) const { + if (!enum_def.is_union) return false; + for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { + const EnumVal& ev = **it; + if (ev.union_type.struct_def && + HasFloatFields(*ev.union_type.struct_def, visited)) + return true; + } + return false; + } + + bool TypeIsHashable(const StructDef& struct_def) const { + std::set visited; + return !HasFloatFields(struct_def, visited); + } + + bool UnionIsHashable(const EnumDef& enum_def) const { + std::set visited; + return !HasFloatFieldsInUnion(enum_def, visited); + } + + // Build the derive string for Object API *T types. + std::string ObjectDerives(bool hashable) const { + std::string derives = "#[derive(Debug, Clone, PartialEq"; + if (hashable) { + derives += ", Eq, Hash"; + } + derives += ")]"; + return derives; + } + + // Check if a namespace defines a table named "String" which would shadow + // std::string::String in Rust Object API types. + bool NamespaceShadowsString(const StructDef& struct_def) const { + if (!struct_def.defined_namespace) return false; + for (auto it = parser_.structs_.vec.begin(); + it != parser_.structs_.vec.end(); ++it) { + const StructDef& other = **it; + if (other.defined_namespace == struct_def.defined_namespace && + other.name == "String") + return true; + } + return false; + } + + // Return the Rust type for a String field in Object API, qualified if needed. + std::string ObjectStringType(const StructDef& struct_def) const { + if (NamespaceShadowsString(struct_def)) { + return "std::string::String"; + } + return "String"; + } + private: IdlNamer namer_; }; diff --git a/tests/arrays_test/my_game/example/array_struct_generated.rs b/tests/arrays_test/my_game/example/array_struct_generated.rs index 834fec39a81..d8cd683a1cc 100644 --- a/tests/arrays_test/my_game/example/array_struct_generated.rs +++ b/tests/arrays_test/my_game/example/array_struct_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct ArrayStruct, aligned to 8 #[repr(transparent)] diff --git a/tests/arrays_test/my_game/example/array_table_generated.rs b/tests/arrays_test/my_game/example/array_table_generated.rs index b0260f6016c..f6dd75cd7cb 100644 --- a/tests/arrays_test/my_game/example/array_table_generated.rs +++ b/tests/arrays_test/my_game/example/array_table_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum ArrayTableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -110,7 +114,6 @@ impl ::core::fmt::Debug for ArrayTable<'_> { ds.finish() } } -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct ArrayTableT { pub a: Option, diff --git a/tests/arrays_test/my_game/example/nested_struct_generated.rs b/tests/arrays_test/my_game/example/nested_struct_generated.rs index db538c211f6..9584ca2e625 100644 --- a/tests/arrays_test/my_game/example/nested_struct_generated.rs +++ b/tests/arrays_test/my_game/example/nested_struct_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct NestedStruct, aligned to 8 #[repr(transparent)] @@ -169,7 +173,7 @@ impl<'a> NestedStruct { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct NestedStructT { pub a: [i32; 2], pub b: TestEnum, diff --git a/tests/arrays_test/my_game/example/test_enum_generated.rs b/tests/arrays_test/my_game/example/test_enum_generated.rs index 572bdae70cb..83b2c236dec 100644 --- a/tests/arrays_test/my_game/example/test_enum_generated.rs +++ b/tests/arrays_test/my_game/example/test_enum_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_TEST_ENUM: i8 = 0; diff --git a/tests/include_test1/my_game/other_name_space/from_include_generated.rs b/tests/include_test1/my_game/other_name_space/from_include_generated.rs index 5eb9adc5eb7..998d843afce 100644 --- a/tests/include_test1/my_game/other_name_space/from_include_generated.rs +++ b/tests/include_test1/my_game/other_name_space/from_include_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_FROM_INCLUDE: i64 = 0; diff --git a/tests/include_test1/my_game/other_name_space/table_b_generated.rs b/tests/include_test1/my_game/other_name_space/table_b_generated.rs index 19a3e66ba9a..6c88726cfcd 100644 --- a/tests/include_test1/my_game/other_name_space/table_b_generated.rs +++ b/tests/include_test1/my_game/other_name_space/table_b_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TableBOffset {} #[derive(Copy, Clone, PartialEq)] @@ -40,7 +44,7 @@ impl<'a> TableB<'a> { pub fn unpack(&self) -> TableBT { let a = self.a().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableBT { a, @@ -110,10 +114,9 @@ impl ::core::fmt::Debug for TableB<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableBT { - pub a: Option>, + pub a: Option>, } impl Default for TableBT { fn default() -> Self { diff --git a/tests/include_test1/my_game/other_name_space/unused_generated.rs b/tests/include_test1/my_game/other_name_space/unused_generated.rs index b90fb892411..18d1cfc61d8 100644 --- a/tests/include_test1/my_game/other_name_space/unused_generated.rs +++ b/tests/include_test1/my_game/other_name_space/unused_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] @@ -106,7 +110,7 @@ impl<'a> Unused { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct UnusedT { pub a: i32, } diff --git a/tests/include_test1/table_a_generated.rs b/tests/include_test1/table_a_generated.rs index ca29250dc3a..54801f70393 100644 --- a/tests/include_test1/table_a_generated.rs +++ b/tests/include_test1/table_a_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -40,7 +44,7 @@ impl<'a> TableA<'a> { pub fn unpack(&self) -> TableAT { let b = self.b().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableAT { b, @@ -110,10 +114,9 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableAT { - pub b: Option>, + pub b: Option>, } impl Default for TableAT { fn default() -> Self { diff --git a/tests/include_test1_generated.rs b/tests/include_test1_generated.rs index c4575b88db2..45791d60a43 100644 --- a/tests/include_test1_generated.rs +++ b/tests/include_test1_generated.rs @@ -2,6 +2,10 @@ // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -41,7 +45,7 @@ impl<'a> TableA<'a> { pub fn unpack(&self) -> TableAT { let b = self.b().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableAT { b, @@ -111,10 +115,9 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableAT { - pub b: Option>, + pub b: Option>, } impl Default for TableAT { fn default() -> Self { @@ -140,10 +143,18 @@ impl TableAT { pub mod my_game { extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; #[allow(unused_imports, dead_code)] pub mod other_name_space { extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_FROM_INCLUDE: i64 = 0; @@ -329,7 +340,7 @@ impl<'a> Unused { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct UnusedT { pub a: i32, } @@ -379,7 +390,7 @@ impl<'a> TableB<'a> { pub fn unpack(&self) -> TableBT { let a = self.a().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableBT { a, @@ -449,10 +460,9 @@ impl ::core::fmt::Debug for TableB<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableBT { - pub a: Option>, + pub a: Option>, } impl Default for TableBT { fn default() -> Self { diff --git a/tests/include_test2/my_game/other_name_space/from_include_generated.rs b/tests/include_test2/my_game/other_name_space/from_include_generated.rs index 5eb9adc5eb7..998d843afce 100644 --- a/tests/include_test2/my_game/other_name_space/from_include_generated.rs +++ b/tests/include_test2/my_game/other_name_space/from_include_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_FROM_INCLUDE: i64 = 0; diff --git a/tests/include_test2/my_game/other_name_space/table_b_generated.rs b/tests/include_test2/my_game/other_name_space/table_b_generated.rs index 19a3e66ba9a..6c88726cfcd 100644 --- a/tests/include_test2/my_game/other_name_space/table_b_generated.rs +++ b/tests/include_test2/my_game/other_name_space/table_b_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TableBOffset {} #[derive(Copy, Clone, PartialEq)] @@ -40,7 +44,7 @@ impl<'a> TableB<'a> { pub fn unpack(&self) -> TableBT { let a = self.a().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableBT { a, @@ -110,10 +114,9 @@ impl ::core::fmt::Debug for TableB<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableBT { - pub a: Option>, + pub a: Option>, } impl Default for TableBT { fn default() -> Self { diff --git a/tests/include_test2/my_game/other_name_space/unused_generated.rs b/tests/include_test2/my_game/other_name_space/unused_generated.rs index b90fb892411..18d1cfc61d8 100644 --- a/tests/include_test2/my_game/other_name_space/unused_generated.rs +++ b/tests/include_test2/my_game/other_name_space/unused_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] @@ -106,7 +110,7 @@ impl<'a> Unused { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct UnusedT { pub a: i32, } diff --git a/tests/include_test2/table_a_generated.rs b/tests/include_test2/table_a_generated.rs index ca29250dc3a..54801f70393 100644 --- a/tests/include_test2/table_a_generated.rs +++ b/tests/include_test2/table_a_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -40,7 +44,7 @@ impl<'a> TableA<'a> { pub fn unpack(&self) -> TableAT { let b = self.b().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableAT { b, @@ -110,10 +114,9 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableAT { - pub b: Option>, + pub b: Option>, } impl Default for TableAT { fn default() -> Self { diff --git a/tests/include_test2_generated.rs b/tests/include_test2_generated.rs index c4575b88db2..45791d60a43 100644 --- a/tests/include_test2_generated.rs +++ b/tests/include_test2_generated.rs @@ -2,6 +2,10 @@ // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -41,7 +45,7 @@ impl<'a> TableA<'a> { pub fn unpack(&self) -> TableAT { let b = self.b().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableAT { b, @@ -111,10 +115,9 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableAT { - pub b: Option>, + pub b: Option>, } impl Default for TableAT { fn default() -> Self { @@ -140,10 +143,18 @@ impl TableAT { pub mod my_game { extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; #[allow(unused_imports, dead_code)] pub mod other_name_space { extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_FROM_INCLUDE: i64 = 0; @@ -329,7 +340,7 @@ impl<'a> Unused { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct UnusedT { pub a: i32, } @@ -379,7 +390,7 @@ impl<'a> TableB<'a> { pub fn unpack(&self) -> TableBT { let a = self.a().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableBT { a, @@ -449,10 +460,9 @@ impl ::core::fmt::Debug for TableB<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableBT { - pub a: Option>, + pub a: Option>, } impl Default for TableBT { fn default() -> Self { diff --git a/tests/keyword_test/keyword_test/abc_generated.rs b/tests/keyword_test/keyword_test/abc_generated.rs index 43df27b6dde..896a46754de 100644 --- a/tests/keyword_test/keyword_test/abc_generated.rs +++ b/tests/keyword_test/keyword_test/abc_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ABC: i32 = 0; diff --git a/tests/keyword_test/keyword_test/keywords_in_table_generated.rs b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs index 1ff91e10037..27e5bf28a32 100644 --- a/tests/keyword_test/keyword_test/keywords_in_table_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum KeywordsInTableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -165,8 +169,7 @@ impl ::core::fmt::Debug for KeywordsInTable<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct KeywordsInTableT { pub is: ABC, pub private: public, diff --git a/tests/keyword_test/keyword_test/keywords_in_union_generated.rs b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs index 88dac0ec62d..8ff2410f640 100644 --- a/tests/keyword_test/keyword_test/keywords_in_union_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_KEYWORDS_IN_UNION: u8 = 0; @@ -93,12 +97,11 @@ impl ::flatbuffers::SimpleToVerifyInSlice for KeywordsInUnion {} pub struct KeywordsInUnionUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum KeywordsInUnionT { NONE, - Static_(alloc::boxed::Box), - Internal(alloc::boxed::Box), + Static_(Box), + Internal(Box), } impl Default for KeywordsInUnionT { fn default() -> Self { @@ -121,7 +124,7 @@ impl KeywordsInUnionT { } } /// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE. - pub fn take_static_(&mut self) -> Option> { + pub fn take_static_(&mut self) -> Option> { if let Self::Static_(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::Static_(w) = v { @@ -142,7 +145,7 @@ impl KeywordsInUnionT { if let Self::Static_(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE. - pub fn take_internal(&mut self) -> Option> { + pub fn take_internal(&mut self) -> Option> { if let Self::Internal(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::Internal(w) = v { diff --git a/tests/keyword_test/keyword_test/public_generated.rs b/tests/keyword_test/keyword_test/public_generated.rs index be9570cc499..674640da46b 100644 --- a/tests/keyword_test/keyword_test/public_generated.rs +++ b/tests/keyword_test/keyword_test/public_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_PUBLIC: i32 = 0; diff --git a/tests/keyword_test/keyword_test/table_2_generated.rs b/tests/keyword_test/keyword_test/table_2_generated.rs index a8e72bd4d08..9290ff6d80c 100644 --- a/tests/keyword_test/keyword_test/table_2_generated.rs +++ b/tests/keyword_test/keyword_test/table_2_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum Table2Offset {} #[derive(Copy, Clone, PartialEq)] @@ -43,12 +47,12 @@ impl<'a> Table2<'a> { pub fn unpack(&self) -> Table2T { let type_ = match self.type_type() { KeywordsInUnion::NONE => KeywordsInUnionT::NONE, - KeywordsInUnion::static_ => KeywordsInUnionT::Static_(alloc::boxed::Box::new( + KeywordsInUnion::static_ => KeywordsInUnionT::Static_(Box::new( self.type__as_static_() .expect("Invalid union table, expected `KeywordsInUnion::static_`.") .unpack() )), - KeywordsInUnion::internal => KeywordsInUnionT::Internal(alloc::boxed::Box::new( + KeywordsInUnion::internal => KeywordsInUnionT::Internal(Box::new( self.type__as_internal() .expect("Invalid union table, expected `KeywordsInUnion::internal`.") .unpack() @@ -192,8 +196,7 @@ impl ::core::fmt::Debug for Table2<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Table2T { pub type_: KeywordsInUnionT, } diff --git a/tests/monster_test/my_game/example/ability_generated.rs b/tests/monster_test/my_game/example/ability_generated.rs index add3b470196..69d2c7f7a24 100644 --- a/tests/monster_test/my_game/example/ability_generated.rs +++ b/tests/monster_test/my_game/example/ability_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct Ability, aligned to 4 #[repr(transparent)] @@ -149,7 +153,7 @@ impl<'a> Ability { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct AbilityT { pub id: u32, pub distance: u32, diff --git a/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs b/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs index af7835dc5bd..bd3ab5857f6 100644 --- a/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs +++ b/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ANY_AMBIGUOUS_ALIASES: u8 = 0; @@ -97,13 +101,12 @@ impl ::flatbuffers::SimpleToVerifyInSlice for AnyAmbiguousAliases {} pub struct AnyAmbiguousAliasesUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub enum AnyAmbiguousAliasesT { NONE, - M1(alloc::boxed::Box), - M2(alloc::boxed::Box), - M3(alloc::boxed::Box), + M1(Box), + M2(Box), + M3(Box), } impl Default for AnyAmbiguousAliasesT { fn default() -> Self { @@ -128,7 +131,7 @@ impl AnyAmbiguousAliasesT { } } /// If the union variant matches, return the owned MonsterT, setting the union to NONE. - pub fn take_m1(&mut self) -> Option> { + pub fn take_m1(&mut self) -> Option> { if let Self::M1(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::M1(w) = v { @@ -149,7 +152,7 @@ impl AnyAmbiguousAliasesT { if let Self::M1(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned MonsterT, setting the union to NONE. - pub fn take_m2(&mut self) -> Option> { + pub fn take_m2(&mut self) -> Option> { if let Self::M2(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::M2(w) = v { @@ -170,7 +173,7 @@ impl AnyAmbiguousAliasesT { if let Self::M2(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned MonsterT, setting the union to NONE. - pub fn take_m3(&mut self) -> Option> { + pub fn take_m3(&mut self) -> Option> { if let Self::M3(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::M3(w) = v { diff --git a/tests/monster_test/my_game/example/any_generated.rs b/tests/monster_test/my_game/example/any_generated.rs index a1da43781a6..0db705be246 100644 --- a/tests/monster_test/my_game/example/any_generated.rs +++ b/tests/monster_test/my_game/example/any_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ANY: u8 = 0; @@ -97,13 +101,12 @@ impl ::flatbuffers::SimpleToVerifyInSlice for Any {} pub struct AnyUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub enum AnyT { NONE, - Monster(alloc::boxed::Box), - TestSimpleTableWithEnum(alloc::boxed::Box), - MyGameExample2Monster(alloc::boxed::Box), + Monster(Box), + TestSimpleTableWithEnum(Box), + MyGameExample2Monster(Box), } impl Default for AnyT { fn default() -> Self { @@ -128,7 +131,7 @@ impl AnyT { } } /// If the union variant matches, return the owned MonsterT, setting the union to NONE. - pub fn take_monster(&mut self) -> Option> { + pub fn take_monster(&mut self) -> Option> { if let Self::Monster(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::Monster(w) = v { @@ -149,7 +152,7 @@ impl AnyT { if let Self::Monster(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE. - pub fn take_test_simple_table_with_enum(&mut self) -> Option> { + pub fn take_test_simple_table_with_enum(&mut self) -> Option> { if let Self::TestSimpleTableWithEnum(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::TestSimpleTableWithEnum(w) = v { @@ -170,7 +173,7 @@ impl AnyT { if let Self::TestSimpleTableWithEnum(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE. - pub fn take_my_game_example_2_monster(&mut self) -> Option> { + pub fn take_my_game_example_2_monster(&mut self) -> Option> { if let Self::MyGameExample2Monster(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::MyGameExample2Monster(w) = v { diff --git a/tests/monster_test/my_game/example/any_unique_aliases_generated.rs b/tests/monster_test/my_game/example/any_unique_aliases_generated.rs index 741f573eec8..260391b31f2 100644 --- a/tests/monster_test/my_game/example/any_unique_aliases_generated.rs +++ b/tests/monster_test/my_game/example/any_unique_aliases_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ANY_UNIQUE_ALIASES: u8 = 0; @@ -97,13 +101,12 @@ impl ::flatbuffers::SimpleToVerifyInSlice for AnyUniqueAliases {} pub struct AnyUniqueAliasesUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub enum AnyUniqueAliasesT { NONE, - M(alloc::boxed::Box), - TS(alloc::boxed::Box), - M2(alloc::boxed::Box), + M(Box), + TS(Box), + M2(Box), } impl Default for AnyUniqueAliasesT { fn default() -> Self { @@ -128,7 +131,7 @@ impl AnyUniqueAliasesT { } } /// If the union variant matches, return the owned MonsterT, setting the union to NONE. - pub fn take_m(&mut self) -> Option> { + pub fn take_m(&mut self) -> Option> { if let Self::M(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::M(w) = v { @@ -149,7 +152,7 @@ impl AnyUniqueAliasesT { if let Self::M(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE. - pub fn take_ts(&mut self) -> Option> { + pub fn take_ts(&mut self) -> Option> { if let Self::TS(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::TS(w) = v { @@ -170,7 +173,7 @@ impl AnyUniqueAliasesT { if let Self::TS(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE. - pub fn take_m2(&mut self) -> Option> { + pub fn take_m2(&mut self) -> Option> { if let Self::M2(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::M2(w) = v { diff --git a/tests/monster_test/my_game/example/color_generated.rs b/tests/monster_test/my_game/example/color_generated.rs index 5bade500f62..a28fa60ecb3 100644 --- a/tests/monster_test/my_game/example/color_generated.rs +++ b/tests/monster_test/my_game/example/color_generated.rs @@ -1,12 +1,16 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[allow(non_upper_case_globals)] mod bitflags_color { ::flatbuffers::bitflags::bitflags! { /// Composite components of Monster color. - #[derive(Default, Debug, Clone, Copy, PartialEq)] + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Color: u8 { const Red = 1; /// \brief color Green diff --git a/tests/monster_test/my_game/example/long_enum_generated.rs b/tests/monster_test/my_game/example/long_enum_generated.rs index efa8f87eaa7..11fbbe79dad 100644 --- a/tests/monster_test/my_game/example/long_enum_generated.rs +++ b/tests/monster_test/my_game/example/long_enum_generated.rs @@ -1,11 +1,15 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[allow(non_upper_case_globals)] mod bitflags_long_enum { ::flatbuffers::bitflags::bitflags! { - #[derive(Default, Debug, Clone, Copy, PartialEq)] + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct LongEnum: u64 { const LongOne = 2; const LongTwo = 4; diff --git a/tests/monster_test/my_game/example/monster_generated.rs b/tests/monster_test/my_game/example/monster_generated.rs index db44ea51d9f..e4bc58a2ac4 100644 --- a/tests/monster_test/my_game/example/monster_generated.rs +++ b/tests/monster_test/my_game/example/monster_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum MonsterOffset {} #[derive(Copy, Clone, PartialEq)] @@ -167,7 +171,7 @@ impl<'a> Monster<'a> { let hp = self.hp(); let name = { let x = self.name(); - alloc::string::ToString::to_string(x) + x.to_string() }; let inventory = self.inventory().map(|x| { x.into_iter().collect() @@ -175,17 +179,17 @@ impl<'a> Monster<'a> { let color = self.color(); let test = match self.test_type() { Any::NONE => AnyT::NONE, - Any::Monster => AnyT::Monster(alloc::boxed::Box::new( + Any::Monster => AnyT::Monster(Box::new( self.test_as_monster() .expect("Invalid union table, expected `Any::Monster`.") .unpack() )), - Any::TestSimpleTableWithEnum => AnyT::TestSimpleTableWithEnum(alloc::boxed::Box::new( + Any::TestSimpleTableWithEnum => AnyT::TestSimpleTableWithEnum(Box::new( self.test_as_test_simple_table_with_enum() .expect("Invalid union table, expected `Any::TestSimpleTableWithEnum`.") .unpack() )), - Any::MyGame_Example2_Monster => AnyT::MyGameExample2Monster(alloc::boxed::Box::new( + Any::MyGame_Example2_Monster => AnyT::MyGameExample2Monster(Box::new( self.test_as_my_game_example_2_monster() .expect("Invalid union table, expected `Any::MyGame_Example2_Monster`.") .unpack() @@ -196,19 +200,19 @@ impl<'a> Monster<'a> { x.iter().map(|t| t.unpack()).collect() }); let testarrayofstring = self.testarrayofstring().map(|x| { - x.iter().map(|s| alloc::string::ToString::to_string(s)).collect() + x.iter().map(|s| s.to_string()).collect() }); let testarrayoftables = self.testarrayoftables().map(|x| { x.iter().map(|t| t.unpack()).collect() }); let enemy = self.enemy().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); let testnestedflatbuffer = self.testnestedflatbuffer().map(|x| { x.into_iter().collect() }); let testempty = self.testempty().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); let testbool = self.testbool(); let testhashs32_fnv1 = self.testhashs32_fnv1(); @@ -226,7 +230,7 @@ impl<'a> Monster<'a> { let testf2 = self.testf2(); let testf3 = self.testf3(); let testarrayofstring2 = self.testarrayofstring2().map(|x| { - x.iter().map(|s| alloc::string::ToString::to_string(s)).collect() + x.iter().map(|s| s.to_string()).collect() }); let testarrayofsortedstruct = self.testarrayofsortedstruct().map(|x| { x.iter().map(|t| t.unpack()).collect() @@ -244,7 +248,7 @@ impl<'a> Monster<'a> { x.into_iter().collect() }); let parent_namespace_test = self.parent_namespace_test().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); let vector_of_referrables = self.vector_of_referrables().map(|x| { x.iter().map(|t| t.unpack()).collect() @@ -266,17 +270,17 @@ impl<'a> Monster<'a> { }); let any_unique = match self.any_unique_type() { AnyUniqueAliases::NONE => AnyUniqueAliasesT::NONE, - AnyUniqueAliases::M => AnyUniqueAliasesT::M(alloc::boxed::Box::new( + AnyUniqueAliases::M => AnyUniqueAliasesT::M(Box::new( self.any_unique_as_m() .expect("Invalid union table, expected `AnyUniqueAliases::M`.") .unpack() )), - AnyUniqueAliases::TS => AnyUniqueAliasesT::TS(alloc::boxed::Box::new( + AnyUniqueAliases::TS => AnyUniqueAliasesT::TS(Box::new( self.any_unique_as_ts() .expect("Invalid union table, expected `AnyUniqueAliases::TS`.") .unpack() )), - AnyUniqueAliases::M2 => AnyUniqueAliasesT::M2(alloc::boxed::Box::new( + AnyUniqueAliases::M2 => AnyUniqueAliasesT::M2(Box::new( self.any_unique_as_m2() .expect("Invalid union table, expected `AnyUniqueAliases::M2`.") .unpack() @@ -285,17 +289,17 @@ impl<'a> Monster<'a> { }; let any_ambiguous = match self.any_ambiguous_type() { AnyAmbiguousAliases::NONE => AnyAmbiguousAliasesT::NONE, - AnyAmbiguousAliases::M1 => AnyAmbiguousAliasesT::M1(alloc::boxed::Box::new( + AnyAmbiguousAliases::M1 => AnyAmbiguousAliasesT::M1(Box::new( self.any_ambiguous_as_m1() .expect("Invalid union table, expected `AnyAmbiguousAliases::M1`.") .unpack() )), - AnyAmbiguousAliases::M2 => AnyAmbiguousAliasesT::M2(alloc::boxed::Box::new( + AnyAmbiguousAliases::M2 => AnyAmbiguousAliasesT::M2(Box::new( self.any_ambiguous_as_m2() .expect("Invalid union table, expected `AnyAmbiguousAliases::M2`.") .unpack() )), - AnyAmbiguousAliases::M3 => AnyAmbiguousAliasesT::M3(alloc::boxed::Box::new( + AnyAmbiguousAliases::M3 => AnyAmbiguousAliasesT::M3(Box::new( self.any_ambiguous_as_m3() .expect("Invalid union table, expected `AnyAmbiguousAliases::M3`.") .unpack() @@ -1612,22 +1616,21 @@ impl ::core::fmt::Debug for Monster<'_> { ds.finish() } } -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MonsterT { pub pos: Option, pub mana: i16, pub hp: i16, - pub name: alloc::string::String, - pub inventory: Option>, + pub name: String, + pub inventory: Option>, pub color: Color, pub test: AnyT, - pub test4: Option>, - pub testarrayofstring: Option>, - pub testarrayoftables: Option>, - pub enemy: Option>, - pub testnestedflatbuffer: Option>, - pub testempty: Option>, + pub test4: Option>, + pub testarrayofstring: Option>, + pub testarrayoftables: Option>, + pub enemy: Option>, + pub testnestedflatbuffer: Option>, + pub testempty: Option>, pub testbool: bool, pub testhashs32_fnv1: i32, pub testhashu32_fnv1: u32, @@ -1637,31 +1640,31 @@ pub struct MonsterT { pub testhashu32_fnv1a: u32, pub testhashs64_fnv1a: i64, pub testhashu64_fnv1a: u64, - pub testarrayofbools: Option>, + pub testarrayofbools: Option>, pub testf: f32, pub testf2: f32, pub testf3: f32, - pub testarrayofstring2: Option>, - pub testarrayofsortedstruct: Option>, - pub flex: Option>, - pub test5: Option>, - pub vector_of_longs: Option>, - pub vector_of_doubles: Option>, - pub parent_namespace_test: Option>, - pub vector_of_referrables: Option>, + pub testarrayofstring2: Option>, + pub testarrayofsortedstruct: Option>, + pub flex: Option>, + pub test5: Option>, + pub vector_of_longs: Option>, + pub vector_of_doubles: Option>, + pub parent_namespace_test: Option>, + pub vector_of_referrables: Option>, pub single_weak_reference: u64, - pub vector_of_weak_references: Option>, - pub vector_of_strong_referrables: Option>, + pub vector_of_weak_references: Option>, + pub vector_of_strong_referrables: Option>, pub co_owning_reference: u64, - pub vector_of_co_owning_references: Option>, + pub vector_of_co_owning_references: Option>, pub non_owning_reference: u64, - pub vector_of_non_owning_references: Option>, + pub vector_of_non_owning_references: Option>, pub any_unique: AnyUniqueAliasesT, pub any_ambiguous: AnyAmbiguousAliasesT, - pub vector_of_enums: Option>, + pub vector_of_enums: Option>, pub signed_enum: Race, - pub testrequirednestedflatbuffer: Option>, - pub scalar_key_sorted_tables: Option>, + pub testrequirednestedflatbuffer: Option>, + pub scalar_key_sorted_tables: Option>, pub native_inline: Option, pub long_enum_non_enum_default: LongEnum, pub long_enum_normal_default: LongEnum, @@ -1680,7 +1683,7 @@ impl Default for MonsterT { pos: None, mana: 150, hp: 100, - name: alloc::string::ToString::to_string(""), + name: "".to_string(), inventory: None, color: Color::Blue, test: AnyT::NONE, @@ -1758,13 +1761,13 @@ impl MonsterT { let test_type = self.test.any_type(); let test = self.test.pack(_fbb); let test4 = self.test4.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) }); let testarrayofstring = self.testarrayofstring.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w) }); let testarrayoftables = self.testarrayoftables.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) }); let enemy = self.enemy.as_ref().map(|x|{ x.pack(_fbb) @@ -1791,16 +1794,16 @@ impl MonsterT { let testf2 = self.testf2; let testf3 = self.testf3; let testarrayofstring2 = self.testarrayofstring2.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w) }); let testarrayofsortedstruct = self.testarrayofsortedstruct.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) }); let flex = self.flex.as_ref().map(|x|{ _fbb.create_vector(x) }); let test5 = self.test5.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) }); let vector_of_longs = self.vector_of_longs.as_ref().map(|x|{ _fbb.create_vector(x) @@ -1812,14 +1815,14 @@ impl MonsterT { x.pack(_fbb) }); let vector_of_referrables = self.vector_of_referrables.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) }); let single_weak_reference = self.single_weak_reference; let vector_of_weak_references = self.vector_of_weak_references.as_ref().map(|x|{ _fbb.create_vector(x) }); let vector_of_strong_referrables = self.vector_of_strong_referrables.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) }); let co_owning_reference = self.co_owning_reference; let vector_of_co_owning_references = self.vector_of_co_owning_references.as_ref().map(|x|{ @@ -1841,7 +1844,7 @@ impl MonsterT { _fbb.create_vector(x) }); let scalar_key_sorted_tables = self.scalar_key_sorted_tables.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) }); let native_inline_tmp = self.native_inline.as_ref().map(|x| x.pack()); let native_inline = native_inline_tmp.as_ref(); diff --git a/tests/monster_test/my_game/example/race_generated.rs b/tests/monster_test/my_game/example/race_generated.rs index 095647f31e2..99306bc0bcc 100644 --- a/tests/monster_test/my_game/example/race_generated.rs +++ b/tests/monster_test/my_game/example/race_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_RACE: i8 = -1; diff --git a/tests/monster_test/my_game/example/referrable_generated.rs b/tests/monster_test/my_game/example/referrable_generated.rs index 08e1f843f67..4991e102bc6 100644 --- a/tests/monster_test/my_game/example/referrable_generated.rs +++ b/tests/monster_test/my_game/example/referrable_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum ReferrableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -118,8 +122,7 @@ impl ::core::fmt::Debug for Referrable<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ReferrableT { pub id: u64, } diff --git a/tests/monster_test/my_game/example/stat_generated.rs b/tests/monster_test/my_game/example/stat_generated.rs index 5f330356c9b..071e2dc1282 100644 --- a/tests/monster_test/my_game/example/stat_generated.rs +++ b/tests/monster_test/my_game/example/stat_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum StatOffset {} #[derive(Copy, Clone, PartialEq)] @@ -44,7 +48,7 @@ impl<'a> Stat<'a> { pub fn unpack(&self) -> StatT { let id = self.id().map(|x| { - alloc::string::ToString::to_string(x) + x.to_string() }); let val = self.val(); let count = self.count(); @@ -158,10 +162,9 @@ impl ::core::fmt::Debug for Stat<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct StatT { - pub id: Option, + pub id: Option, pub val: i64, pub count: u16, } diff --git a/tests/monster_test/my_game/example/struct_of_structs_generated.rs b/tests/monster_test/my_game/example/struct_of_structs_generated.rs index 05d1a4feffa..8c14cbc06df 100644 --- a/tests/monster_test/my_game/example/struct_of_structs_generated.rs +++ b/tests/monster_test/my_game/example/struct_of_structs_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct StructOfStructs, aligned to 4 #[repr(transparent)] @@ -121,7 +125,7 @@ impl<'a> StructOfStructs { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct StructOfStructsT { pub a: AbilityT, pub b: TestT, diff --git a/tests/monster_test/my_game/example/struct_of_structs_of_structs_generated.rs b/tests/monster_test/my_game/example/struct_of_structs_of_structs_generated.rs index a0fd05524e6..bf7b150b0ec 100644 --- a/tests/monster_test/my_game/example/struct_of_structs_of_structs_generated.rs +++ b/tests/monster_test/my_game/example/struct_of_structs_of_structs_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct StructOfStructsOfStructs, aligned to 4 #[repr(transparent)] @@ -89,7 +93,7 @@ impl<'a> StructOfStructsOfStructs { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct StructOfStructsOfStructsT { pub a: StructOfStructsT, } diff --git a/tests/monster_test/my_game/example/test_generated.rs b/tests/monster_test/my_game/example/test_generated.rs index 178cbe99c4e..47abe379b4a 100644 --- a/tests/monster_test/my_game/example/test_generated.rs +++ b/tests/monster_test/my_game/example/test_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct Test, aligned to 2 #[repr(transparent)] @@ -139,7 +143,7 @@ impl<'a> Test { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct TestT { pub a: i16, pub b: i8, diff --git a/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs b/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs index c264d4969ad..cce783c6849 100644 --- a/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs +++ b/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TestSimpleTableWithEnumOffset {} #[derive(Copy, Clone, PartialEq)] @@ -108,8 +112,7 @@ impl ::core::fmt::Debug for TestSimpleTableWithEnum<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TestSimpleTableWithEnumT { pub color: Color, } diff --git a/tests/monster_test/my_game/example/type_aliases_generated.rs b/tests/monster_test/my_game/example/type_aliases_generated.rs index b7788ebdfb8..2ed5f929c86 100644 --- a/tests/monster_test/my_game/example/type_aliases_generated.rs +++ b/tests/monster_test/my_game/example/type_aliases_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TypeAliasesOffset {} #[derive(Copy, Clone, PartialEq)] @@ -321,7 +325,6 @@ impl ::core::fmt::Debug for TypeAliases<'_> { ds.finish() } } -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TypeAliasesT { pub i8_: i8, @@ -334,8 +337,8 @@ pub struct TypeAliasesT { pub u64_: u64, pub f32_: f32, pub f64_: f64, - pub v8: Option>, - pub vf64: Option>, + pub v8: Option>, + pub vf64: Option>, } impl Default for TypeAliasesT { fn default() -> Self { diff --git a/tests/monster_test/my_game/example/vec_3_generated.rs b/tests/monster_test/my_game/example/vec_3_generated.rs index 2b2872bc61a..bedcd29185a 100644 --- a/tests/monster_test/my_game/example/vec_3_generated.rs +++ b/tests/monster_test/my_game/example/vec_3_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct Vec3, aligned to 8 #[repr(transparent)] diff --git a/tests/monster_test/my_game/example_2/monster_generated.rs b/tests/monster_test/my_game/example_2/monster_generated.rs index 7e2409ff5b0..242fee52eb2 100644 --- a/tests/monster_test/my_game/example_2/monster_generated.rs +++ b/tests/monster_test/my_game/example_2/monster_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum MonsterOffset {} #[derive(Copy, Clone, PartialEq)] @@ -88,8 +92,7 @@ impl ::core::fmt::Debug for Monster<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct MonsterT { } impl Default for MonsterT { diff --git a/tests/monster_test/my_game/in_parent_namespace_generated.rs b/tests/monster_test/my_game/in_parent_namespace_generated.rs index 7bcb4be7fa6..10da41c5274 100644 --- a/tests/monster_test/my_game/in_parent_namespace_generated.rs +++ b/tests/monster_test/my_game/in_parent_namespace_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum InParentNamespaceOffset {} #[derive(Copy, Clone, PartialEq)] @@ -88,8 +92,7 @@ impl ::core::fmt::Debug for InParentNamespace<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct InParentNamespaceT { } impl Default for InParentNamespaceT { diff --git a/tests/monster_test/my_game/other_name_space/from_include_generated.rs b/tests/monster_test/my_game/other_name_space/from_include_generated.rs index 5eb9adc5eb7..998d843afce 100644 --- a/tests/monster_test/my_game/other_name_space/from_include_generated.rs +++ b/tests/monster_test/my_game/other_name_space/from_include_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_FROM_INCLUDE: i64 = 0; diff --git a/tests/monster_test/my_game/other_name_space/table_b_generated.rs b/tests/monster_test/my_game/other_name_space/table_b_generated.rs index 19a3e66ba9a..6c88726cfcd 100644 --- a/tests/monster_test/my_game/other_name_space/table_b_generated.rs +++ b/tests/monster_test/my_game/other_name_space/table_b_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TableBOffset {} #[derive(Copy, Clone, PartialEq)] @@ -40,7 +44,7 @@ impl<'a> TableB<'a> { pub fn unpack(&self) -> TableBT { let a = self.a().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableBT { a, @@ -110,10 +114,9 @@ impl ::core::fmt::Debug for TableB<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableBT { - pub a: Option>, + pub a: Option>, } impl Default for TableBT { fn default() -> Self { diff --git a/tests/monster_test/my_game/other_name_space/unused_generated.rs b/tests/monster_test/my_game/other_name_space/unused_generated.rs index b90fb892411..18d1cfc61d8 100644 --- a/tests/monster_test/my_game/other_name_space/unused_generated.rs +++ b/tests/monster_test/my_game/other_name_space/unused_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] @@ -106,7 +110,7 @@ impl<'a> Unused { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct UnusedT { pub a: i32, } diff --git a/tests/monster_test/table_a_generated.rs b/tests/monster_test/table_a_generated.rs index ca29250dc3a..54801f70393 100644 --- a/tests/monster_test/table_a_generated.rs +++ b/tests/monster_test/table_a_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -40,7 +44,7 @@ impl<'a> TableA<'a> { pub fn unpack(&self) -> TableAT { let b = self.b().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableAT { b, @@ -110,10 +114,9 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableAT { - pub b: Option>, + pub b: Option>, } impl Default for TableAT { fn default() -> Self { diff --git a/tests/monster_test_serialize/my_game/example/ability_generated.rs b/tests/monster_test_serialize/my_game/example/ability_generated.rs index eb9846058ae..3aef32d1adf 100644 --- a/tests/monster_test_serialize/my_game/example/ability_generated.rs +++ b/tests/monster_test_serialize/my_game/example/ability_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -163,7 +167,7 @@ impl<'a> Ability { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct AbilityT { pub id: u32, pub distance: u32, diff --git a/tests/monster_test_serialize/my_game/example/any_ambiguous_aliases_generated.rs b/tests/monster_test_serialize/my_game/example/any_ambiguous_aliases_generated.rs index 647e85416a0..d542c3de7fa 100644 --- a/tests/monster_test_serialize/my_game/example/any_ambiguous_aliases_generated.rs +++ b/tests/monster_test_serialize/my_game/example/any_ambiguous_aliases_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -69,7 +73,7 @@ impl<'de> serde::Deserialize<'de> for AnyAmbiguousAliases { where D: serde::Deserializer<'de>, { - let s = String::deserialize(deserializer)?; + let s = ::deserialize(deserializer)?; for item in AnyAmbiguousAliases::ENUM_VALUES { if let Some(item_name) = item.variant_name() { if item_name == s { @@ -127,13 +131,12 @@ impl ::flatbuffers::SimpleToVerifyInSlice for AnyAmbiguousAliases {} pub struct AnyAmbiguousAliasesUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub enum AnyAmbiguousAliasesT { NONE, - M1(alloc::boxed::Box), - M2(alloc::boxed::Box), - M3(alloc::boxed::Box), + M1(Box), + M2(Box), + M3(Box), } impl Default for AnyAmbiguousAliasesT { fn default() -> Self { @@ -158,7 +161,7 @@ impl AnyAmbiguousAliasesT { } } /// If the union variant matches, return the owned MonsterT, setting the union to NONE. - pub fn take_m1(&mut self) -> Option> { + pub fn take_m1(&mut self) -> Option> { if let Self::M1(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::M1(w) = v { @@ -179,7 +182,7 @@ impl AnyAmbiguousAliasesT { if let Self::M1(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned MonsterT, setting the union to NONE. - pub fn take_m2(&mut self) -> Option> { + pub fn take_m2(&mut self) -> Option> { if let Self::M2(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::M2(w) = v { @@ -200,7 +203,7 @@ impl AnyAmbiguousAliasesT { if let Self::M2(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned MonsterT, setting the union to NONE. - pub fn take_m3(&mut self) -> Option> { + pub fn take_m3(&mut self) -> Option> { if let Self::M3(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::M3(w) = v { diff --git a/tests/monster_test_serialize/my_game/example/any_generated.rs b/tests/monster_test_serialize/my_game/example/any_generated.rs index f5b40b5e3af..f63c0353ff4 100644 --- a/tests/monster_test_serialize/my_game/example/any_generated.rs +++ b/tests/monster_test_serialize/my_game/example/any_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -69,7 +73,7 @@ impl<'de> serde::Deserialize<'de> for Any { where D: serde::Deserializer<'de>, { - let s = String::deserialize(deserializer)?; + let s = ::deserialize(deserializer)?; for item in Any::ENUM_VALUES { if let Some(item_name) = item.variant_name() { if item_name == s { @@ -127,13 +131,12 @@ impl ::flatbuffers::SimpleToVerifyInSlice for Any {} pub struct AnyUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub enum AnyT { NONE, - Monster(alloc::boxed::Box), - TestSimpleTableWithEnum(alloc::boxed::Box), - MyGameExample2Monster(alloc::boxed::Box), + Monster(Box), + TestSimpleTableWithEnum(Box), + MyGameExample2Monster(Box), } impl Default for AnyT { fn default() -> Self { @@ -158,7 +161,7 @@ impl AnyT { } } /// If the union variant matches, return the owned MonsterT, setting the union to NONE. - pub fn take_monster(&mut self) -> Option> { + pub fn take_monster(&mut self) -> Option> { if let Self::Monster(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::Monster(w) = v { @@ -179,7 +182,7 @@ impl AnyT { if let Self::Monster(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE. - pub fn take_test_simple_table_with_enum(&mut self) -> Option> { + pub fn take_test_simple_table_with_enum(&mut self) -> Option> { if let Self::TestSimpleTableWithEnum(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::TestSimpleTableWithEnum(w) = v { @@ -200,7 +203,7 @@ impl AnyT { if let Self::TestSimpleTableWithEnum(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE. - pub fn take_my_game_example_2_monster(&mut self) -> Option> { + pub fn take_my_game_example_2_monster(&mut self) -> Option> { if let Self::MyGameExample2Monster(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::MyGameExample2Monster(w) = v { diff --git a/tests/monster_test_serialize/my_game/example/any_unique_aliases_generated.rs b/tests/monster_test_serialize/my_game/example/any_unique_aliases_generated.rs index 2128e47795a..492acb41d47 100644 --- a/tests/monster_test_serialize/my_game/example/any_unique_aliases_generated.rs +++ b/tests/monster_test_serialize/my_game/example/any_unique_aliases_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -69,7 +73,7 @@ impl<'de> serde::Deserialize<'de> for AnyUniqueAliases { where D: serde::Deserializer<'de>, { - let s = String::deserialize(deserializer)?; + let s = ::deserialize(deserializer)?; for item in AnyUniqueAliases::ENUM_VALUES { if let Some(item_name) = item.variant_name() { if item_name == s { @@ -127,13 +131,12 @@ impl ::flatbuffers::SimpleToVerifyInSlice for AnyUniqueAliases {} pub struct AnyUniqueAliasesUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub enum AnyUniqueAliasesT { NONE, - M(alloc::boxed::Box), - TS(alloc::boxed::Box), - M2(alloc::boxed::Box), + M(Box), + TS(Box), + M2(Box), } impl Default for AnyUniqueAliasesT { fn default() -> Self { @@ -158,7 +161,7 @@ impl AnyUniqueAliasesT { } } /// If the union variant matches, return the owned MonsterT, setting the union to NONE. - pub fn take_m(&mut self) -> Option> { + pub fn take_m(&mut self) -> Option> { if let Self::M(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::M(w) = v { @@ -179,7 +182,7 @@ impl AnyUniqueAliasesT { if let Self::M(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE. - pub fn take_ts(&mut self) -> Option> { + pub fn take_ts(&mut self) -> Option> { if let Self::TS(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::TS(w) = v { @@ -200,7 +203,7 @@ impl AnyUniqueAliasesT { if let Self::TS(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE. - pub fn take_m2(&mut self) -> Option> { + pub fn take_m2(&mut self) -> Option> { if let Self::M2(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::M2(w) = v { diff --git a/tests/monster_test_serialize/my_game/example/color_generated.rs b/tests/monster_test_serialize/my_game/example/color_generated.rs index 5a540612b5c..94ce11c37e2 100644 --- a/tests/monster_test_serialize/my_game/example/color_generated.rs +++ b/tests/monster_test_serialize/my_game/example/color_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -8,7 +12,7 @@ use super::*; mod bitflags_color { ::flatbuffers::bitflags::bitflags! { /// Composite components of Monster color. - #[derive(Default, Debug, Clone, Copy, PartialEq)] + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Color: u8 { const Red = 1; /// \brief color Green diff --git a/tests/monster_test_serialize/my_game/example/long_enum_generated.rs b/tests/monster_test_serialize/my_game/example/long_enum_generated.rs index bff530afeed..492bb96c523 100644 --- a/tests/monster_test_serialize/my_game/example/long_enum_generated.rs +++ b/tests/monster_test_serialize/my_game/example/long_enum_generated.rs @@ -1,13 +1,17 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; #[allow(non_upper_case_globals)] mod bitflags_long_enum { ::flatbuffers::bitflags::bitflags! { - #[derive(Default, Debug, Clone, Copy, PartialEq)] + #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct LongEnum: u64 { const LongOne = 2; const LongTwo = 4; diff --git a/tests/monster_test_serialize/my_game/example/monster_generated.rs b/tests/monster_test_serialize/my_game/example/monster_generated.rs index 749098f5680..68d042b24ee 100644 --- a/tests/monster_test_serialize/my_game/example/monster_generated.rs +++ b/tests/monster_test_serialize/my_game/example/monster_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -169,7 +173,7 @@ impl<'a> Monster<'a> { let hp = self.hp(); let name = { let x = self.name(); - alloc::string::ToString::to_string(x) + x.to_string() }; let inventory = self.inventory().map(|x| { x.into_iter().collect() @@ -177,17 +181,17 @@ impl<'a> Monster<'a> { let color = self.color(); let test = match self.test_type() { Any::NONE => AnyT::NONE, - Any::Monster => AnyT::Monster(alloc::boxed::Box::new( + Any::Monster => AnyT::Monster(Box::new( self.test_as_monster() .expect("Invalid union table, expected `Any::Monster`.") .unpack() )), - Any::TestSimpleTableWithEnum => AnyT::TestSimpleTableWithEnum(alloc::boxed::Box::new( + Any::TestSimpleTableWithEnum => AnyT::TestSimpleTableWithEnum(Box::new( self.test_as_test_simple_table_with_enum() .expect("Invalid union table, expected `Any::TestSimpleTableWithEnum`.") .unpack() )), - Any::MyGame_Example2_Monster => AnyT::MyGameExample2Monster(alloc::boxed::Box::new( + Any::MyGame_Example2_Monster => AnyT::MyGameExample2Monster(Box::new( self.test_as_my_game_example_2_monster() .expect("Invalid union table, expected `Any::MyGame_Example2_Monster`.") .unpack() @@ -198,19 +202,19 @@ impl<'a> Monster<'a> { x.iter().map(|t| t.unpack()).collect() }); let testarrayofstring = self.testarrayofstring().map(|x| { - x.iter().map(|s| alloc::string::ToString::to_string(s)).collect() + x.iter().map(|s| s.to_string()).collect() }); let testarrayoftables = self.testarrayoftables().map(|x| { x.iter().map(|t| t.unpack()).collect() }); let enemy = self.enemy().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); let testnestedflatbuffer = self.testnestedflatbuffer().map(|x| { x.into_iter().collect() }); let testempty = self.testempty().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); let testbool = self.testbool(); let testhashs32_fnv1 = self.testhashs32_fnv1(); @@ -228,7 +232,7 @@ impl<'a> Monster<'a> { let testf2 = self.testf2(); let testf3 = self.testf3(); let testarrayofstring2 = self.testarrayofstring2().map(|x| { - x.iter().map(|s| alloc::string::ToString::to_string(s)).collect() + x.iter().map(|s| s.to_string()).collect() }); let testarrayofsortedstruct = self.testarrayofsortedstruct().map(|x| { x.iter().map(|t| t.unpack()).collect() @@ -246,7 +250,7 @@ impl<'a> Monster<'a> { x.into_iter().collect() }); let parent_namespace_test = self.parent_namespace_test().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); let vector_of_referrables = self.vector_of_referrables().map(|x| { x.iter().map(|t| t.unpack()).collect() @@ -268,17 +272,17 @@ impl<'a> Monster<'a> { }); let any_unique = match self.any_unique_type() { AnyUniqueAliases::NONE => AnyUniqueAliasesT::NONE, - AnyUniqueAliases::M => AnyUniqueAliasesT::M(alloc::boxed::Box::new( + AnyUniqueAliases::M => AnyUniqueAliasesT::M(Box::new( self.any_unique_as_m() .expect("Invalid union table, expected `AnyUniqueAliases::M`.") .unpack() )), - AnyUniqueAliases::TS => AnyUniqueAliasesT::TS(alloc::boxed::Box::new( + AnyUniqueAliases::TS => AnyUniqueAliasesT::TS(Box::new( self.any_unique_as_ts() .expect("Invalid union table, expected `AnyUniqueAliases::TS`.") .unpack() )), - AnyUniqueAliases::M2 => AnyUniqueAliasesT::M2(alloc::boxed::Box::new( + AnyUniqueAliases::M2 => AnyUniqueAliasesT::M2(Box::new( self.any_unique_as_m2() .expect("Invalid union table, expected `AnyUniqueAliases::M2`.") .unpack() @@ -287,17 +291,17 @@ impl<'a> Monster<'a> { }; let any_ambiguous = match self.any_ambiguous_type() { AnyAmbiguousAliases::NONE => AnyAmbiguousAliasesT::NONE, - AnyAmbiguousAliases::M1 => AnyAmbiguousAliasesT::M1(alloc::boxed::Box::new( + AnyAmbiguousAliases::M1 => AnyAmbiguousAliasesT::M1(Box::new( self.any_ambiguous_as_m1() .expect("Invalid union table, expected `AnyAmbiguousAliases::M1`.") .unpack() )), - AnyAmbiguousAliases::M2 => AnyAmbiguousAliasesT::M2(alloc::boxed::Box::new( + AnyAmbiguousAliases::M2 => AnyAmbiguousAliasesT::M2(Box::new( self.any_ambiguous_as_m2() .expect("Invalid union table, expected `AnyAmbiguousAliases::M2`.") .unpack() )), - AnyAmbiguousAliases::M3 => AnyAmbiguousAliasesT::M3(alloc::boxed::Box::new( + AnyAmbiguousAliases::M3 => AnyAmbiguousAliasesT::M3(Box::new( self.any_ambiguous_as_m3() .expect("Invalid union table, expected `AnyAmbiguousAliases::M3`.") .unpack() @@ -1839,22 +1843,21 @@ impl ::core::fmt::Debug for Monster<'_> { ds.finish() } } -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MonsterT { pub pos: Option, pub mana: i16, pub hp: i16, - pub name: alloc::string::String, - pub inventory: Option>, + pub name: String, + pub inventory: Option>, pub color: Color, pub test: AnyT, - pub test4: Option>, - pub testarrayofstring: Option>, - pub testarrayoftables: Option>, - pub enemy: Option>, - pub testnestedflatbuffer: Option>, - pub testempty: Option>, + pub test4: Option>, + pub testarrayofstring: Option>, + pub testarrayoftables: Option>, + pub enemy: Option>, + pub testnestedflatbuffer: Option>, + pub testempty: Option>, pub testbool: bool, pub testhashs32_fnv1: i32, pub testhashu32_fnv1: u32, @@ -1864,31 +1867,31 @@ pub struct MonsterT { pub testhashu32_fnv1a: u32, pub testhashs64_fnv1a: i64, pub testhashu64_fnv1a: u64, - pub testarrayofbools: Option>, + pub testarrayofbools: Option>, pub testf: f32, pub testf2: f32, pub testf3: f32, - pub testarrayofstring2: Option>, - pub testarrayofsortedstruct: Option>, - pub flex: Option>, - pub test5: Option>, - pub vector_of_longs: Option>, - pub vector_of_doubles: Option>, - pub parent_namespace_test: Option>, - pub vector_of_referrables: Option>, + pub testarrayofstring2: Option>, + pub testarrayofsortedstruct: Option>, + pub flex: Option>, + pub test5: Option>, + pub vector_of_longs: Option>, + pub vector_of_doubles: Option>, + pub parent_namespace_test: Option>, + pub vector_of_referrables: Option>, pub single_weak_reference: u64, - pub vector_of_weak_references: Option>, - pub vector_of_strong_referrables: Option>, + pub vector_of_weak_references: Option>, + pub vector_of_strong_referrables: Option>, pub co_owning_reference: u64, - pub vector_of_co_owning_references: Option>, + pub vector_of_co_owning_references: Option>, pub non_owning_reference: u64, - pub vector_of_non_owning_references: Option>, + pub vector_of_non_owning_references: Option>, pub any_unique: AnyUniqueAliasesT, pub any_ambiguous: AnyAmbiguousAliasesT, - pub vector_of_enums: Option>, + pub vector_of_enums: Option>, pub signed_enum: Race, - pub testrequirednestedflatbuffer: Option>, - pub scalar_key_sorted_tables: Option>, + pub testrequirednestedflatbuffer: Option>, + pub scalar_key_sorted_tables: Option>, pub native_inline: Option, pub long_enum_non_enum_default: LongEnum, pub long_enum_normal_default: LongEnum, @@ -1907,7 +1910,7 @@ impl Default for MonsterT { pos: None, mana: 150, hp: 100, - name: alloc::string::ToString::to_string(""), + name: "".to_string(), inventory: None, color: Color::Blue, test: AnyT::NONE, @@ -1985,13 +1988,13 @@ impl MonsterT { let test_type = self.test.any_type(); let test = self.test.pack(_fbb); let test4 = self.test4.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) }); let testarrayofstring = self.testarrayofstring.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w) }); let testarrayoftables = self.testarrayoftables.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) }); let enemy = self.enemy.as_ref().map(|x|{ x.pack(_fbb) @@ -2018,16 +2021,16 @@ impl MonsterT { let testf2 = self.testf2; let testf3 = self.testf3; let testarrayofstring2 = self.testarrayofstring2.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w) }); let testarrayofsortedstruct = self.testarrayofsortedstruct.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) }); let flex = self.flex.as_ref().map(|x|{ _fbb.create_vector(x) }); let test5 = self.test5.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w) }); let vector_of_longs = self.vector_of_longs.as_ref().map(|x|{ _fbb.create_vector(x) @@ -2039,14 +2042,14 @@ impl MonsterT { x.pack(_fbb) }); let vector_of_referrables = self.vector_of_referrables.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) }); let single_weak_reference = self.single_weak_reference; let vector_of_weak_references = self.vector_of_weak_references.as_ref().map(|x|{ _fbb.create_vector(x) }); let vector_of_strong_referrables = self.vector_of_strong_referrables.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) }); let co_owning_reference = self.co_owning_reference; let vector_of_co_owning_references = self.vector_of_co_owning_references.as_ref().map(|x|{ @@ -2068,7 +2071,7 @@ impl MonsterT { _fbb.create_vector(x) }); let scalar_key_sorted_tables = self.scalar_key_sorted_tables.as_ref().map(|x|{ - let w: alloc::vec::Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) + let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w) }); let native_inline_tmp = self.native_inline.as_ref().map(|x| x.pack()); let native_inline = native_inline_tmp.as_ref(); diff --git a/tests/monster_test_serialize/my_game/example/race_generated.rs b/tests/monster_test_serialize/my_game/example/race_generated.rs index c91c401a3f2..b1e9b1cdd3f 100644 --- a/tests/monster_test_serialize/my_game/example/race_generated.rs +++ b/tests/monster_test_serialize/my_game/example/race_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -69,7 +73,7 @@ impl<'de> serde::Deserialize<'de> for Race { where D: serde::Deserializer<'de>, { - let s = String::deserialize(deserializer)?; + let s = ::deserialize(deserializer)?; for item in Race::ENUM_VALUES { if let Some(item_name) = item.variant_name() { if item_name == s { diff --git a/tests/monster_test_serialize/my_game/example/referrable_generated.rs b/tests/monster_test_serialize/my_game/example/referrable_generated.rs index eed359a0173..7019f1f6a6a 100644 --- a/tests/monster_test_serialize/my_game/example/referrable_generated.rs +++ b/tests/monster_test_serialize/my_game/example/referrable_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -131,8 +135,7 @@ impl ::core::fmt::Debug for Referrable<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ReferrableT { pub id: u64, } diff --git a/tests/monster_test_serialize/my_game/example/stat_generated.rs b/tests/monster_test_serialize/my_game/example/stat_generated.rs index af34edba8d5..92be82d28d1 100644 --- a/tests/monster_test_serialize/my_game/example/stat_generated.rs +++ b/tests/monster_test_serialize/my_game/example/stat_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -46,7 +50,7 @@ impl<'a> Stat<'a> { pub fn unpack(&self) -> StatT { let id = self.id().map(|x| { - alloc::string::ToString::to_string(x) + x.to_string() }); let val = self.val(); let count = self.count(); @@ -177,10 +181,9 @@ impl ::core::fmt::Debug for Stat<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct StatT { - pub id: Option, + pub id: Option, pub val: i64, pub count: u16, } diff --git a/tests/monster_test_serialize/my_game/example/struct_of_structs_generated.rs b/tests/monster_test_serialize/my_game/example/struct_of_structs_generated.rs index 23236d77d88..a7b2d35b64e 100644 --- a/tests/monster_test_serialize/my_game/example/struct_of_structs_generated.rs +++ b/tests/monster_test_serialize/my_game/example/struct_of_structs_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -136,7 +140,7 @@ impl<'a> StructOfStructs { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct StructOfStructsT { pub a: AbilityT, pub b: TestT, diff --git a/tests/monster_test_serialize/my_game/example/struct_of_structs_of_structs_generated.rs b/tests/monster_test_serialize/my_game/example/struct_of_structs_of_structs_generated.rs index 0751e5b3335..49f7ba44e76 100644 --- a/tests/monster_test_serialize/my_game/example/struct_of_structs_of_structs_generated.rs +++ b/tests/monster_test_serialize/my_game/example/struct_of_structs_of_structs_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -102,7 +106,7 @@ impl<'a> StructOfStructsOfStructs { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct StructOfStructsOfStructsT { pub a: StructOfStructsT, } diff --git a/tests/monster_test_serialize/my_game/example/test_generated.rs b/tests/monster_test_serialize/my_game/example/test_generated.rs index b8c2e041f49..8e12e075b0d 100644 --- a/tests/monster_test_serialize/my_game/example/test_generated.rs +++ b/tests/monster_test_serialize/my_game/example/test_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -153,7 +157,7 @@ impl<'a> Test { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct TestT { pub a: i16, pub b: i8, diff --git a/tests/monster_test_serialize/my_game/example/test_simple_table_with_enum_generated.rs b/tests/monster_test_serialize/my_game/example/test_simple_table_with_enum_generated.rs index df0a4689275..bdb3b852b5e 100644 --- a/tests/monster_test_serialize/my_game/example/test_simple_table_with_enum_generated.rs +++ b/tests/monster_test_serialize/my_game/example/test_simple_table_with_enum_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -121,8 +125,7 @@ impl ::core::fmt::Debug for TestSimpleTableWithEnum<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TestSimpleTableWithEnumT { pub color: Color, } diff --git a/tests/monster_test_serialize/my_game/example/type_aliases_generated.rs b/tests/monster_test_serialize/my_game/example/type_aliases_generated.rs index 7ec1728b73c..52be107a1dc 100644 --- a/tests/monster_test_serialize/my_game/example/type_aliases_generated.rs +++ b/tests/monster_test_serialize/my_game/example/type_aliases_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -353,7 +357,6 @@ impl ::core::fmt::Debug for TypeAliases<'_> { ds.finish() } } -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TypeAliasesT { pub i8_: i8, @@ -366,8 +369,8 @@ pub struct TypeAliasesT { pub u64_: u64, pub f32_: f32, pub f64_: f64, - pub v8: Option>, - pub vf64: Option>, + pub v8: Option>, + pub vf64: Option>, } impl Default for TypeAliasesT { fn default() -> Self { diff --git a/tests/monster_test_serialize/my_game/example/vec_3_generated.rs b/tests/monster_test_serialize/my_game/example/vec_3_generated.rs index a1afa825154..a3c43d65466 100644 --- a/tests/monster_test_serialize/my_game/example/vec_3_generated.rs +++ b/tests/monster_test_serialize/my_game/example/vec_3_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; diff --git a/tests/monster_test_serialize/my_game/example_2/monster_generated.rs b/tests/monster_test_serialize/my_game/example_2/monster_generated.rs index 4faf3108925..dc7e36bf631 100644 --- a/tests/monster_test_serialize/my_game/example_2/monster_generated.rs +++ b/tests/monster_test_serialize/my_game/example_2/monster_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -100,8 +104,7 @@ impl ::core::fmt::Debug for Monster<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct MonsterT { } impl Default for MonsterT { diff --git a/tests/monster_test_serialize/my_game/in_parent_namespace_generated.rs b/tests/monster_test_serialize/my_game/in_parent_namespace_generated.rs index 2f3723ea52c..35abb081a8e 100644 --- a/tests/monster_test_serialize/my_game/in_parent_namespace_generated.rs +++ b/tests/monster_test_serialize/my_game/in_parent_namespace_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -100,8 +104,7 @@ impl ::core::fmt::Debug for InParentNamespace<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct InParentNamespaceT { } impl Default for InParentNamespaceT { diff --git a/tests/monster_test_serialize/my_game/other_name_space/from_include_generated.rs b/tests/monster_test_serialize/my_game/other_name_space/from_include_generated.rs index 84d5602ae73..a37d88540e6 100644 --- a/tests/monster_test_serialize/my_game/other_name_space/from_include_generated.rs +++ b/tests/monster_test_serialize/my_game/other_name_space/from_include_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -57,7 +61,7 @@ impl<'de> serde::Deserialize<'de> for FromInclude { where D: serde::Deserializer<'de>, { - let s = String::deserialize(deserializer)?; + let s = ::deserialize(deserializer)?; for item in FromInclude::ENUM_VALUES { if let Some(item_name) = item.variant_name() { if item_name == s { diff --git a/tests/monster_test_serialize/my_game/other_name_space/table_b_generated.rs b/tests/monster_test_serialize/my_game/other_name_space/table_b_generated.rs index ecb57c54f0b..6d647c732f7 100644 --- a/tests/monster_test_serialize/my_game/other_name_space/table_b_generated.rs +++ b/tests/monster_test_serialize/my_game/other_name_space/table_b_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -42,7 +46,7 @@ impl<'a> TableB<'a> { pub fn unpack(&self) -> TableBT { let a = self.a().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableBT { a, @@ -127,10 +131,9 @@ impl ::core::fmt::Debug for TableB<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableBT { - pub a: Option>, + pub a: Option>, } impl Default for TableBT { fn default() -> Self { diff --git a/tests/monster_test_serialize/my_game/other_name_space/unused_generated.rs b/tests/monster_test_serialize/my_game/other_name_space/unused_generated.rs index 0d5f2240a7e..27a24192a24 100644 --- a/tests/monster_test_serialize/my_game/other_name_space/unused_generated.rs +++ b/tests/monster_test_serialize/my_game/other_name_space/unused_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -119,7 +123,7 @@ impl<'a> Unused { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct UnusedT { pub a: i32, } diff --git a/tests/monster_test_serialize/table_a_generated.rs b/tests/monster_test_serialize/table_a_generated.rs index a3c1ba60886..947af56a87c 100644 --- a/tests/monster_test_serialize/table_a_generated.rs +++ b/tests/monster_test_serialize/table_a_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; @@ -42,7 +46,7 @@ impl<'a> TableA<'a> { pub fn unpack(&self) -> TableAT { let b = self.b().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableAT { b, @@ -127,10 +131,9 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableAT { - pub b: Option>, + pub b: Option>, } impl Default for TableAT { fn default() -> Self { diff --git a/tests/monsterdata_python_wire.mon b/tests/monsterdata_python_wire.mon index 2fb956d58c95ec10cd50bb7f811e99a71c455a4d..f91503b693582ac21d11336128cb6abb17fb0b0e 100644 GIT binary patch delta 18 Zcmcb?bc1QaA9gMV5e7L1jmgZ6p#V2(1egE- delta 18 Zcmcb?bc1QaA9gtg4F)a-k;%-Ap#V4v1egE- diff --git a/tests/more_defaults/abc_generated.rs b/tests/more_defaults/abc_generated.rs index c41b406000b..fb752c2d2ac 100644 --- a/tests/more_defaults/abc_generated.rs +++ b/tests/more_defaults/abc_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ABC: i32 = 0; diff --git a/tests/more_defaults/more_defaults_generated.rs b/tests/more_defaults/more_defaults_generated.rs index 72dd9dbcb63..45144409ef1 100644 --- a/tests/more_defaults/more_defaults_generated.rs +++ b/tests/more_defaults/more_defaults_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum MoreDefaultsOffset {} #[derive(Copy, Clone, PartialEq)] @@ -59,11 +63,11 @@ impl<'a> MoreDefaults<'a> { }; let empty_string = { let x = self.empty_string(); - alloc::string::ToString::to_string(x) + x.to_string() }; let some_string = { let x = self.some_string(); - alloc::string::ToString::to_string(x) + x.to_string() }; let abcs = { let x = self.abcs(); @@ -221,23 +225,22 @@ impl ::core::fmt::Debug for MoreDefaults<'_> { ds.finish() } } -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MoreDefaultsT { - pub ints: alloc::vec::Vec, - pub floats: alloc::vec::Vec, - pub empty_string: alloc::string::String, - pub some_string: alloc::string::String, - pub abcs: alloc::vec::Vec, - pub bools: alloc::vec::Vec, + pub ints: Vec, + pub floats: Vec, + pub empty_string: String, + pub some_string: String, + pub abcs: Vec, + pub bools: Vec, } impl Default for MoreDefaultsT { fn default() -> Self { Self { ints: Default::default(), floats: Default::default(), - empty_string: alloc::string::ToString::to_string(""), - some_string: alloc::string::ToString::to_string("some"), + empty_string: "".to_string(), + some_string: "some".to_string(), abcs: Default::default(), bools: Default::default(), } diff --git a/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs index 51724c62ab4..fffeeec1a2b 100644 --- a/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ENUM_IN_NESTED_NS: i8 = 0; diff --git a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs index b6b8c381298..34e481f2090 100644 --- a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct StructInNestedNS, aligned to 4 #[repr(transparent)] @@ -139,7 +143,7 @@ impl<'a> StructInNestedNS { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub struct StructInNestedNST { pub a: i32, pub b: i32, diff --git a/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs index e90a7497537..98b057ea5ce 100644 --- a/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TableInNestedNSOffset {} #[derive(Copy, Clone, PartialEq)] @@ -108,8 +112,7 @@ impl ::core::fmt::Debug for TableInNestedNS<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableInNestedNST { pub foo: i32, } diff --git a/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs index 3e636d1e7ee..3371ef620b4 100644 --- a/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_UNION_IN_NESTED_NS: u8 = 0; @@ -89,11 +93,10 @@ impl ::flatbuffers::SimpleToVerifyInSlice for UnionInNestedNS {} pub struct UnionInNestedNSUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum UnionInNestedNST { NONE, - TableInNestedNS(alloc::boxed::Box), + TableInNestedNS(Box), } impl Default for UnionInNestedNST { fn default() -> Self { @@ -114,7 +117,7 @@ impl UnionInNestedNST { } } /// If the union variant matches, return the owned TableInNestedNST, setting the union to NONE. - pub fn take_table_in_nested_ns(&mut self) -> Option> { + pub fn take_table_in_nested_ns(&mut self) -> Option> { if let Self::TableInNestedNS(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::TableInNestedNS(w) = v { diff --git a/tests/namespace_test/namespace_a/second_table_in_a_generated.rs b/tests/namespace_test/namespace_a/second_table_in_a_generated.rs index d4a2abf91e6..1589f3fd2f2 100644 --- a/tests/namespace_test/namespace_a/second_table_in_a_generated.rs +++ b/tests/namespace_test/namespace_a/second_table_in_a_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum SecondTableInAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -40,7 +44,7 @@ impl<'a> SecondTableInA<'a> { pub fn unpack(&self) -> SecondTableInAT { let refer_to_c = self.refer_to_c().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); SecondTableInAT { refer_to_c, @@ -110,10 +114,9 @@ impl ::core::fmt::Debug for SecondTableInA<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SecondTableInAT { - pub refer_to_c: Option>, + pub refer_to_c: Option>, } impl Default for SecondTableInAT { fn default() -> Self { diff --git a/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs b/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs index b3d0cfe1c18..41d39f2406d 100644 --- a/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs +++ b/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TableInFirstNSOffset {} #[derive(Copy, Clone, PartialEq)] @@ -48,12 +52,12 @@ impl<'a> TableInFirstNS<'a> { pub fn unpack(&self) -> TableInFirstNST { let foo_table = self.foo_table().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); let foo_enum = self.foo_enum(); let foo_union = match self.foo_union_type() { namespace_b::UnionInNestedNS::NONE => namespace_b::UnionInNestedNST::NONE, - namespace_b::UnionInNestedNS::TableInNestedNS => namespace_b::UnionInNestedNST::TableInNestedNS(alloc::boxed::Box::new( + namespace_b::UnionInNestedNS::TableInNestedNS => namespace_b::UnionInNestedNST::TableInNestedNS(Box::new( self.foo_union_as_table_in_nested_ns() .expect("Invalid union table, expected `namespace_b::UnionInNestedNS::TableInNestedNS`.") .unpack() @@ -225,10 +229,9 @@ impl ::core::fmt::Debug for TableInFirstNS<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableInFirstNST { - pub foo_table: Option>, + pub foo_table: Option>, pub foo_enum: namespace_b::EnumInNestedNS, pub foo_union: namespace_b::UnionInNestedNST, pub foo_struct: Option, diff --git a/tests/namespace_test/namespace_c/table_in_c_generated.rs b/tests/namespace_test/namespace_c/table_in_c_generated.rs index f1e2e669723..1561aa73425 100644 --- a/tests/namespace_test/namespace_c/table_in_c_generated.rs +++ b/tests/namespace_test/namespace_c/table_in_c_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum TableInCOffset {} #[derive(Copy, Clone, PartialEq)] @@ -42,10 +46,10 @@ impl<'a> TableInC<'a> { pub fn unpack(&self) -> TableInCT { let refer_to_a1 = self.refer_to_a1().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); let refer_to_a2 = self.refer_to_a2().map(|x| { - alloc::boxed::Box::new(x.unpack()) + Box::new(x.unpack()) }); TableInCT { refer_to_a1, @@ -131,11 +135,10 @@ impl ::core::fmt::Debug for TableInC<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TableInCT { - pub refer_to_a1: Option>, - pub refer_to_a2: Option>, + pub refer_to_a1: Option>, + pub refer_to_a2: Option>, } impl Default for TableInCT { fn default() -> Self { diff --git a/tests/optional_scalars/optional_scalars/optional_byte_generated.rs b/tests/optional_scalars/optional_scalars/optional_byte_generated.rs index a0b1c4d3960..2c66663f48b 100644 --- a/tests/optional_scalars/optional_scalars/optional_byte_generated.rs +++ b/tests/optional_scalars/optional_scalars/optional_byte_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_OPTIONAL_BYTE: i8 = 0; diff --git a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs index 79052ff4b1f..e90b360b4f1 100644 --- a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs +++ b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum ScalarStuffOffset {} #[derive(Copy, Clone, PartialEq)] @@ -773,7 +777,6 @@ impl ::core::fmt::Debug for ScalarStuff<'_> { ds.finish() } } -#[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct ScalarStuffT { pub just_i8: i8, diff --git a/tests/private_annotation_test/ab_generated.rs b/tests/private_annotation_test/ab_generated.rs index c8fd77cc07f..e779a888b71 100644 --- a/tests/private_annotation_test/ab_generated.rs +++ b/tests/private_annotation_test/ab_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_AB: i8 = 0; diff --git a/tests/private_annotation_test/annotations_generated.rs b/tests/private_annotation_test/annotations_generated.rs index 3db01a9fbc2..c6fbfeeaff9 100644 --- a/tests/private_annotation_test/annotations_generated.rs +++ b/tests/private_annotation_test/annotations_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub(crate) enum AnnotationsOffset {} #[derive(Copy, Clone, PartialEq)] @@ -108,8 +112,7 @@ impl ::core::fmt::Debug for Annotations<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub(crate) struct AnnotationsT { pub value: i32, } diff --git a/tests/private_annotation_test/any_generated.rs b/tests/private_annotation_test/any_generated.rs index dd6aed8a275..4c969e5d632 100644 --- a/tests/private_annotation_test/any_generated.rs +++ b/tests/private_annotation_test/any_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ANY: u8 = 0; @@ -93,12 +97,11 @@ impl ::flatbuffers::SimpleToVerifyInSlice for Any {} pub(crate) struct AnyUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub(crate) enum AnyT { NONE, - Game(alloc::boxed::Box), - Annotations(alloc::boxed::Box), + Game(Box), + Annotations(Box), } impl Default for AnyT { fn default() -> Self { @@ -121,7 +124,7 @@ impl AnyT { } } /// If the union variant matches, return the owned GameT, setting the union to NONE. - pub fn take_game(&mut self) -> Option> { + pub fn take_game(&mut self) -> Option> { if let Self::Game(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::Game(w) = v { @@ -142,7 +145,7 @@ impl AnyT { if let Self::Game(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned AnnotationsT, setting the union to NONE. - pub fn take_annotations(&mut self) -> Option> { + pub fn take_annotations(&mut self) -> Option> { if let Self::Annotations(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::Annotations(w) = v { diff --git a/tests/private_annotation_test/game_generated.rs b/tests/private_annotation_test/game_generated.rs index b43ce1885c9..70e0e888cbf 100644 --- a/tests/private_annotation_test/game_generated.rs +++ b/tests/private_annotation_test/game_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub(crate) enum GameOffset {} #[derive(Copy, Clone, PartialEq)] @@ -108,8 +112,7 @@ impl ::core::fmt::Debug for Game<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub(crate) struct GameT { pub value: i32, } diff --git a/tests/private_annotation_test/object_generated.rs b/tests/private_annotation_test/object_generated.rs index 5e98d992705..3a47ede2cd9 100644 --- a/tests/private_annotation_test/object_generated.rs +++ b/tests/private_annotation_test/object_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct Object, aligned to 4 #[repr(transparent)] @@ -106,7 +110,7 @@ impl<'a> Object { } } -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, PartialEq, Default, Eq, Hash)] pub(crate) struct ObjectT { pub value: i32, } diff --git a/tests/rust_namer_test/rust_namer_test/field_table_generated.rs b/tests/rust_namer_test/rust_namer_test/field_table_generated.rs index 63256505b20..fd4047d9e4c 100644 --- a/tests/rust_namer_test/rust_namer_test/field_table_generated.rs +++ b/tests/rust_namer_test/rust_namer_test/field_table_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum FieldTableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -88,8 +92,7 @@ impl ::core::fmt::Debug for FieldTable<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FieldTableT { } impl Default for FieldTableT { diff --git a/tests/rust_namer_test/rust_namer_test/field_union_generated.rs b/tests/rust_namer_test/rust_namer_test/field_union_generated.rs index 70883590bcc..78bdaf0c83a 100644 --- a/tests/rust_namer_test/rust_namer_test/field_union_generated.rs +++ b/tests/rust_namer_test/rust_namer_test/field_union_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_FIELD_UNION: u8 = 0; @@ -89,11 +93,10 @@ impl ::flatbuffers::SimpleToVerifyInSlice for FieldUnion {} pub struct FieldUnionUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum FieldUnionT { NONE, - F(alloc::boxed::Box), + F(Box), } impl Default for FieldUnionT { fn default() -> Self { @@ -114,7 +117,7 @@ impl FieldUnionT { } } /// If the union variant matches, return the owned FieldTableT, setting the union to NONE. - pub fn take_f(&mut self) -> Option> { + pub fn take_f(&mut self) -> Option> { if let Self::F(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::F(w) = v { diff --git a/tests/rust_namer_test/rust_namer_test/game_message_generated.rs b/tests/rust_namer_test/rust_namer_test/game_message_generated.rs index 47d0a990a96..365adcacda5 100644 --- a/tests/rust_namer_test/rust_namer_test/game_message_generated.rs +++ b/tests/rust_namer_test/rust_namer_test/game_message_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_GAME_MESSAGE: u8 = 0; @@ -97,13 +101,12 @@ impl ::flatbuffers::SimpleToVerifyInSlice for GameMessage {} pub struct GameMessageUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum GameMessageT { NONE, - PlayerStatEvent(alloc::boxed::Box), - PlayerSpectate(alloc::boxed::Box), - PlayerInputChange(alloc::boxed::Box), + PlayerStatEvent(Box), + PlayerSpectate(Box), + PlayerInputChange(Box), } impl Default for GameMessageT { fn default() -> Self { @@ -128,7 +131,7 @@ impl GameMessageT { } } /// If the union variant matches, return the owned PlayerStatEventT, setting the union to NONE. - pub fn take_player_stat_event(&mut self) -> Option> { + pub fn take_player_stat_event(&mut self) -> Option> { if let Self::PlayerStatEvent(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::PlayerStatEvent(w) = v { @@ -149,7 +152,7 @@ impl GameMessageT { if let Self::PlayerStatEvent(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned PlayerSpectateT, setting the union to NONE. - pub fn take_player_spectate(&mut self) -> Option> { + pub fn take_player_spectate(&mut self) -> Option> { if let Self::PlayerSpectate(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::PlayerSpectate(w) = v { @@ -170,7 +173,7 @@ impl GameMessageT { if let Self::PlayerSpectate(v) = self { Some(v.as_mut()) } else { None } } /// If the union variant matches, return the owned PlayerInputChangeT, setting the union to NONE. - pub fn take_player_input_change(&mut self) -> Option> { + pub fn take_player_input_change(&mut self) -> Option> { if let Self::PlayerInputChange(_) = self { let v = ::core::mem::replace(self, Self::NONE); if let Self::PlayerInputChange(w) = v { diff --git a/tests/rust_namer_test/rust_namer_test/game_message_wrapper_generated.rs b/tests/rust_namer_test/rust_namer_test/game_message_wrapper_generated.rs index 9c8adbee4e2..8d6dc06d53b 100644 --- a/tests/rust_namer_test/rust_namer_test/game_message_wrapper_generated.rs +++ b/tests/rust_namer_test/rust_namer_test/game_message_wrapper_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum GameMessageWrapperOffset {} #[derive(Copy, Clone, PartialEq)] @@ -43,17 +47,17 @@ impl<'a> GameMessageWrapper<'a> { pub fn unpack(&self) -> GameMessageWrapperT { let Message = match self.Message_type() { GameMessage::NONE => GameMessageT::NONE, - GameMessage::PlayerStatEvent => GameMessageT::PlayerStatEvent(alloc::boxed::Box::new( + GameMessage::PlayerStatEvent => GameMessageT::PlayerStatEvent(Box::new( self.Message_as_player_stat_event() .expect("Invalid union table, expected `GameMessage::PlayerStatEvent`.") .unpack() )), - GameMessage::PlayerSpectate => GameMessageT::PlayerSpectate(alloc::boxed::Box::new( + GameMessage::PlayerSpectate => GameMessageT::PlayerSpectate(Box::new( self.Message_as_player_spectate() .expect("Invalid union table, expected `GameMessage::PlayerSpectate`.") .unpack() )), - GameMessage::PlayerInputChange => GameMessageT::PlayerInputChange(alloc::boxed::Box::new( + GameMessage::PlayerInputChange => GameMessageT::PlayerInputChange(Box::new( self.Message_as_player_input_change() .expect("Invalid union table, expected `GameMessage::PlayerInputChange`.") .unpack() @@ -220,8 +224,7 @@ impl ::core::fmt::Debug for GameMessageWrapper<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct GameMessageWrapperT { pub Message: GameMessageT, } diff --git a/tests/rust_namer_test/rust_namer_test/player_input_change_generated.rs b/tests/rust_namer_test/rust_namer_test/player_input_change_generated.rs index ef0645421ae..d73edc69157 100644 --- a/tests/rust_namer_test/rust_namer_test/player_input_change_generated.rs +++ b/tests/rust_namer_test/rust_namer_test/player_input_change_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum PlayerInputChangeOffset {} #[derive(Copy, Clone, PartialEq)] @@ -88,8 +92,7 @@ impl ::core::fmt::Debug for PlayerInputChange<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PlayerInputChangeT { } impl Default for PlayerInputChangeT { diff --git a/tests/rust_namer_test/rust_namer_test/player_spectate_generated.rs b/tests/rust_namer_test/rust_namer_test/player_spectate_generated.rs index 40b2066c03c..e138d3dc56c 100644 --- a/tests/rust_namer_test/rust_namer_test/player_spectate_generated.rs +++ b/tests/rust_namer_test/rust_namer_test/player_spectate_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum PlayerSpectateOffset {} #[derive(Copy, Clone, PartialEq)] @@ -88,8 +92,7 @@ impl ::core::fmt::Debug for PlayerSpectate<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PlayerSpectateT { } impl Default for PlayerSpectateT { diff --git a/tests/rust_namer_test/rust_namer_test/player_stat_event_generated.rs b/tests/rust_namer_test/rust_namer_test/player_stat_event_generated.rs index 7fe60fad9c3..cffbf81a6ac 100644 --- a/tests/rust_namer_test/rust_namer_test/player_stat_event_generated.rs +++ b/tests/rust_namer_test/rust_namer_test/player_stat_event_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum PlayerStatEventOffset {} #[derive(Copy, Clone, PartialEq)] @@ -88,8 +92,7 @@ impl ::core::fmt::Debug for PlayerStatEvent<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PlayerStatEventT { } impl Default for PlayerStatEventT { diff --git a/tests/rust_namer_test/rust_namer_test/possibly_reserved_words_generated.rs b/tests/rust_namer_test/rust_namer_test/possibly_reserved_words_generated.rs index 6d4ec11e2bb..082a812e674 100644 --- a/tests/rust_namer_test/rust_namer_test/possibly_reserved_words_generated.rs +++ b/tests/rust_namer_test/rust_namer_test/possibly_reserved_words_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; // struct PossiblyReservedWords, aligned to 4 #[repr(transparent)] diff --git a/tests/rust_namer_test/rust_namer_test/root_table_generated.rs b/tests/rust_namer_test/rust_namer_test/root_table_generated.rs index c3d458e0774..0b282ab79ac 100644 --- a/tests/rust_namer_test/rust_namer_test/root_table_generated.rs +++ b/tests/rust_namer_test/rust_namer_test/root_table_generated.rs @@ -1,6 +1,10 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated extern crate alloc; +use alloc::vec::Vec; +use alloc::string::String; +use alloc::boxed::Box; +use alloc::string::ToString; use super::*; pub enum RootTableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -43,7 +47,7 @@ impl<'a> RootTable<'a> { pub fn unpack(&self) -> RootTableT { let field42 = match self.field42_type() { FieldUnion::NONE => FieldUnionT::NONE, - FieldUnion::f => FieldUnionT::F(alloc::boxed::Box::new( + FieldUnion::f => FieldUnionT::F(Box::new( self.field42_as_f() .expect("Invalid union table, expected `FieldUnion::f`.") .unpack() @@ -164,8 +168,7 @@ impl ::core::fmt::Debug for RootTable<'_> { ds.finish() } } -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RootTableT { pub field42: FieldUnionT, } diff --git a/tests/service_test_generated.py b/tests/service_test_generated.py index b87026f89dd..1fa9b099a07 100644 --- a/tests/service_test_generated.py +++ b/tests/service_test_generated.py @@ -3,11 +3,12 @@ # namespace: example import flatbuffers +from typing import Any class HelloRequest(object): __slots__ = ['_tab'] @classmethod - def GetRootAs(cls, buf, offset=0): + def GetRootAs(cls, buf, offset: int = 0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = HelloRequest() x.Init(buf, n + offset) @@ -18,13 +19,13 @@ def GetRootAsHelloRequest(cls, buf, offset=0): """This method is deprecated. Please switch to GetRootAs.""" return cls.GetRootAs(buf, offset) # HelloRequest - def Init(self, buf, pos): + def Init(self, buf: bytes, pos: int): self._tab = flatbuffers.table.Table(buf, pos) -def HelloRequestStart(builder): +def HelloRequestStart(builder: flatbuffers.Builder): builder.StartObject(0) -def HelloRequestEnd(builder): +def HelloRequestEnd(builder: flatbuffers.Builder) -> int: return builder.EndObject() @@ -33,7 +34,7 @@ class HelloResponse(object): __slots__ = ['_tab'] @classmethod - def GetRootAs(cls, buf, offset=0): + def GetRootAs(cls, buf, offset: int = 0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = HelloResponse() x.Init(buf, n + offset) @@ -44,13 +45,13 @@ def GetRootAsHelloResponse(cls, buf, offset=0): """This method is deprecated. Please switch to GetRootAs.""" return cls.GetRootAs(buf, offset) # HelloResponse - def Init(self, buf, pos): + def Init(self, buf: bytes, pos: int): self._tab = flatbuffers.table.Table(buf, pos) -def HelloResponseStart(builder): +def HelloResponseStart(builder: flatbuffers.Builder): builder.StartObject(0) -def HelloResponseEnd(builder): +def HelloResponseEnd(builder: flatbuffers.Builder) -> int: return builder.EndObject() From bc818fef7c0bf45b4a98e49b424df6e0a75ad9fe Mon Sep 17 00:00:00 2001 From: pittengermdp Date: Thu, 19 Feb 2026 10:53:42 -0600 Subject: [PATCH 2/3] C++ test fixes --- tests/64bit/evolution/v2_generated.h | 1 - tests/64bit/test_64bit_bfbs_generated.h | 10 +++++----- tests/64bit/test_64bit_generated.h | 5 ----- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tests/64bit/evolution/v2_generated.h b/tests/64bit/evolution/v2_generated.h index d3f06cdb302..671667b7c76 100644 --- a/tests/64bit/evolution/v2_generated.h +++ b/tests/64bit/evolution/v2_generated.h @@ -105,7 +105,6 @@ inline ::flatbuffers::Offset CreateRootTable( ::flatbuffers::Offset<::flatbuffers::Vector> b = 0, ::flatbuffers::Offset64<::flatbuffers::Vector64> big_vector = 0) { RootTableBuilder builder_(_fbb); - builder_.add_big_vector(big_vector); builder_.add_b(b); builder_.add_a(a); return builder_.Finish(); diff --git a/tests/64bit/test_64bit_bfbs_generated.h b/tests/64bit/test_64bit_bfbs_generated.h index 58fab1bc08e..ccb4a8347a2 100644 --- a/tests/64bit/test_64bit_bfbs_generated.h +++ b/tests/64bit/test_64bit_bfbs_generated.h @@ -22,30 +22,30 @@ struct RootTableBinarySchema { 0xA8,0x02,0x00,0x00,0x20,0x00,0x00,0x00,0x5C,0x00,0x00,0x00,0x7C,0x01,0x00,0x00,0x28,0x01,0x00,0x00, 0x09,0x00,0x00,0x00,0x52,0x6F,0x6F,0x74,0x54,0x61,0x62,0x6C,0x65,0x00,0x00,0x00,0xF0,0xFD,0xFF,0xFF, 0x00,0x00,0x01,0x01,0x0A,0x00,0x18,0x00,0x18,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x38,0xFE,0xFF,0xFF, - 0x00,0x00,0x12,0x04,0x08,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x00,0x00,0x00,0x66,0x6F,0x72,0x63, + 0x00,0x00,0x12,0x04,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x15,0x00,0x00,0x00,0x66,0x6F,0x72,0x63, 0x65,0x64,0x5F,0x61,0x6C,0x69,0x67,0x6E,0x65,0x64,0x5F,0x76,0x65,0x63,0x74,0x6F,0x72,0x00,0x00,0x00, 0xF8,0xFE,0xFF,0xFF,0x00,0x00,0x00,0x01,0x09,0x00,0x16,0x00,0x18,0x00,0x00,0x00,0x04,0x00,0x00,0x00, 0x78,0xFF,0xFF,0xFF,0x00,0x00,0x0E,0x0F,0x02,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x0C,0x00,0x00,0x00, 0x6D,0x61,0x6E,0x79,0x5F,0x76,0x65,0x63,0x74,0x6F,0x72,0x73,0x00,0x00,0x00,0x00,0x68,0xFE,0xFF,0xFF, 0x00,0x00,0x01,0x01,0x08,0x00,0x14,0x00,0x2C,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x10,0x00,0x14,0x00, 0x06,0x00,0x07,0x00,0x08,0x00,0x00,0x00,0x0C,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x12,0x0F, - 0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x62,0x69,0x67,0x5F, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x62,0x69,0x67,0x5F, 0x73,0x74,0x72,0x75,0x63,0x74,0x5F,0x76,0x65,0x63,0x74,0x6F,0x72,0x00,0x00,0x00,0xB8,0xFE,0xFF,0xFF, 0x00,0x00,0x01,0x01,0x07,0x00,0x12,0x00,0x28,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x10,0x00,0x10,0x00, 0x06,0x00,0x07,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x0E,0x0F, 0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x11,0x00,0x00,0x00,0x66,0x61,0x72,0x5F,0x73,0x74,0x72,0x75, 0x63,0x74,0x5F,0x76,0x65,0x63,0x74,0x6F,0x72,0x00,0x00,0x00,0x04,0xFF,0xFF,0xFF,0x00,0x00,0x01,0x01, 0x06,0x00,0x10,0x00,0x18,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x4C,0xFF,0xFF,0xFF,0x00,0x00,0x12,0x04, - 0x08,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x0B,0x00,0x00,0x00,0x6E,0x65,0x73,0x74,0x65,0x64,0x5F,0x72, + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x0B,0x00,0x00,0x00,0x6E,0x65,0x73,0x74,0x65,0x64,0x5F,0x72, 0x6F,0x6F,0x74,0x00,0x1C,0x00,0x14,0x00,0x0C,0x00,0x10,0x00,0x08,0x00,0x0A,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x01, 0x05,0x00,0x0E,0x00,0x14,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x58,0xFD,0xFF,0xFF,0x00,0x00,0x00,0x0D, 0x01,0x00,0x00,0x00,0x0B,0x00,0x00,0x00,0x6E,0x65,0x61,0x72,0x5F,0x73,0x74,0x72,0x69,0x6E,0x67,0x00, 0x84,0xFF,0xFF,0xFF,0x00,0x00,0x01,0x01,0x04,0x00,0x0C,0x00,0x18,0x00,0x00,0x00,0x04,0x00,0x00,0x00, - 0xCC,0xFF,0xFF,0xFF,0x00,0x00,0x12,0x04,0x08,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x0A,0x00,0x00,0x00, + 0xCC,0xFF,0xFF,0xFF,0x00,0x00,0x12,0x04,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x0A,0x00,0x00,0x00, 0x62,0x69,0x67,0x5F,0x76,0x65,0x63,0x74,0x6F,0x72,0x00,0x00,0xB8,0xFF,0xFF,0xFF,0x00,0x00,0x01,0x01, 0x03,0x00,0x0A,0x00,0x28,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x06,0x00,0x07,0x00, - 0x00,0x00,0x00,0x00,0x08,0x00,0x0C,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x12,0x04,0x08,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x08,0x00,0x0C,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x12,0x04,0x00,0x00,0x00,0x00, 0x01,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x62,0x69,0x67,0x5F,0x62,0x6F,0x6F,0x6C,0x5F,0x76,0x65,0x63, 0x74,0x6F,0x72,0x00,0x20,0x00,0x14,0x00,0x0C,0x00,0x10,0x00,0x08,0x00,0x0A,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x07,0x00,0x20,0x00,0x00,0x00, diff --git a/tests/64bit/test_64bit_generated.h b/tests/64bit/test_64bit_generated.h index bd255c5c10b..f5e012921f6 100644 --- a/tests/64bit/test_64bit_generated.h +++ b/tests/64bit/test_64bit_generated.h @@ -362,11 +362,6 @@ inline ::flatbuffers::Offset CreateRootTable( ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> many_vectors = 0, ::flatbuffers::Offset64<::flatbuffers::Vector64> forced_aligned_vector = 0) { RootTableBuilder builder_(_fbb); - builder_.add_forced_aligned_vector(forced_aligned_vector); - builder_.add_big_struct_vector(big_struct_vector); - builder_.add_nested_root(nested_root); - builder_.add_big_vector(big_vector); - builder_.add_big_bool_vector(big_bool_vector); builder_.add_many_vectors(many_vectors); builder_.add_far_struct_vector(far_struct_vector); builder_.add_near_string(near_string); From 54a8d3fc5391faec7a1dc23a44f1ff52fe0f5e23 Mon Sep 17 00:00:00 2001 From: pittengermdp Date: Thu, 19 Feb 2026 11:26:05 -0600 Subject: [PATCH 3/3] [Rust] Add serde derives to Object API *T types when --rust-serialize is enabled The ObjectDerives() function was adding Eq/Hash but missing serde::Serialize/Deserialize when the --rust-serialize flag was active. This caused regenerated code to lose serde derives on *T types. --- src/idl_gen_rust.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index 05cf3319037..49292b4e83d 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -376,9 +376,15 @@ class RustGenerator : public BaseGenerator { code_ += "// @generated"; code_ += "extern crate alloc;"; if (parser_.opts.generate_object_based_api) { + code_ += "#[allow(unused_imports)]"; code_ += "use alloc::vec::Vec;"; - code_ += "use alloc::string::String;"; + if (!AnyNamespaceHasStringTable()) { + code_ += "#[allow(unused_imports)]"; + code_ += "use alloc::string::String;"; + } + code_ += "#[allow(unused_imports)]"; code_ += "use alloc::boxed::Box;"; + code_ += "#[allow(unused_imports)]"; code_ += "use alloc::string::ToString;"; } if (parser_.opts.rust_serialize) { @@ -3022,9 +3028,15 @@ class RustGenerator : public BaseGenerator { } code_ += "extern crate alloc;"; if (parser_.opts.generate_object_based_api) { + code_ += "#[allow(unused_imports)]"; code_ += "use alloc::vec::Vec;"; - code_ += "use alloc::string::String;"; + if (!AnyNamespaceHasStringTable()) { + code_ += "#[allow(unused_imports)]"; + code_ += "use alloc::string::String;"; + } + code_ += "#[allow(unused_imports)]"; code_ += "use alloc::boxed::Box;"; + code_ += "#[allow(unused_imports)]"; code_ += "use alloc::string::ToString;"; } } @@ -3131,10 +3143,25 @@ class RustGenerator : public BaseGenerator { if (hashable) { derives += ", Eq, Hash"; } + if (parser_.opts.rust_serialize) { + derives += ", serde::Serialize, serde::Deserialize"; + } derives += ")]"; return derives; } + // Check if any namespace in the schema defines a table named "String". + // When true, we must not emit `use alloc::string::String;` because it + // would shadow the FlatBuffer String table type in generated code. + bool AnyNamespaceHasStringTable() const { + for (auto it = parser_.structs_.vec.begin(); + it != parser_.structs_.vec.end(); ++it) { + const StructDef& other = **it; + if (other.name == "String") return true; + } + return false; + } + // Check if a namespace defines a table named "String" which would shadow // std::string::String in Rust Object API types. bool NamespaceShadowsString(const StructDef& struct_def) const {