From 0a9ea4d13057ed2af52675d422982d7884d8ce64 Mon Sep 17 00:00:00 2001 From: Cameron Mulhern Date: Mon, 22 Dec 2025 10:04:31 -0500 Subject: [PATCH 1/2] Cleans up Rust formatting --- src/idl_gen_rust.cpp | 140 ++++++++++++++++++++++++++++++++----------- 1 file changed, 106 insertions(+), 34 deletions(-) diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index b7a565d00cd..398475f801e 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -429,8 +429,7 @@ class RustGenerator : public BaseGenerator { // Generate imports for the global scope in case no namespace is used // in the schema file. - GenNamespaceImports(0); - code_ += ""; + GenNamespaceImports(); // Generate all code in their namespaces, once, because Rust does not // permit re-opening modules. @@ -708,6 +707,8 @@ class RustGenerator : public BaseGenerator { // an enum match function, // and an enum array of values void GenEnum(const EnumDef& enum_def) { + code_ += ""; + const bool is_private = parser_.opts.no_leak_private_annotations && (enum_def.attributes.Lookup("private") != nullptr); code_.SetValue("ACCESS_TYPE", is_private ? "pub(crate)" : "pub"); @@ -739,6 +740,8 @@ class RustGenerator : public BaseGenerator { code_ += " }"; code_ += " }"; code_ += "}"; + code_ += ""; + code_ += "pub use self::bitflags_{{ENUM_NAMESPACE}}::{{ENUM_TY}};"; code_ += ""; @@ -753,10 +756,14 @@ class RustGenerator : public BaseGenerator { code_ += "pub const ENUM_MIN_{{ENUM_CONSTANT}}: {{BASE_TYPE}}" " = {{ENUM_MIN_BASE_VALUE}};"; + code_ += ""; + code_ += deprecation_warning; code_ += "pub const ENUM_MAX_{{ENUM_CONSTANT}}: {{BASE_TYPE}}" " = {{ENUM_MAX_BASE_VALUE}};"; + code_ += ""; + auto num_fields = NumToString(enum_def.size()); code_ += deprecation_warning; code_ += "#[allow(non_camel_case_types)]"; @@ -777,6 +784,8 @@ class RustGenerator : public BaseGenerator { "Default)]"; code_ += "#[repr(transparent)]"; code_ += "{{ACCESS_TYPE}} struct {{ENUM_TY}}(pub {{BASE_TYPE}});"; + code_ += ""; + code_ += "#[allow(non_upper_case_globals)]"; code_ += "impl {{ENUM_TY}} {"; ForAllEnumValues1(enum_def, [&](const EnumVal& ev) { @@ -790,6 +799,8 @@ class RustGenerator : public BaseGenerator { code_ += " pub const ENUM_VALUES: &'static [Self] = &["; ForAllEnumValues(enum_def, [&]() { code_ += " Self::{{VARIANT}},"; }); code_ += " ];"; + code_ += ""; + code_ += " /// Returns the variant's name or \"\" if unknown."; code_ += " pub fn variant_name(self) -> Option<&'static str> {"; code_ += " match self {"; @@ -800,6 +811,7 @@ class RustGenerator : public BaseGenerator { code_ += " }"; code_ += " }"; code_ += "}"; + code_ += ""; // Generate Debug. Unknown variants are printed like "". code_ += "impl ::core::fmt::Debug for {{ENUM_TY}} {"; @@ -813,6 +825,7 @@ class RustGenerator : public BaseGenerator { code_ += " }"; code_ += " }"; code_ += "}"; + code_ += ""; code_.SetValue("INTO_BASE", "self.0"); } @@ -864,6 +877,7 @@ class RustGenerator : public BaseGenerator { // Generate Follow and Push so we can serialize and stuff. code_ += "impl<'a> ::flatbuffers::Follow<'a> for {{ENUM_TY}} {"; code_ += " type Inner = Self;"; + code_ += ""; code_ += " #[inline]"; code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {"; code_ += @@ -879,6 +893,7 @@ class RustGenerator : public BaseGenerator { code_ += ""; code_ += "impl ::flatbuffers::Push for {{ENUM_TY}} {"; code_ += " type Output = {{ENUM_TY}};"; + code_ += ""; code_ += " #[inline]"; code_ += " unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {"; code_ += @@ -889,10 +904,12 @@ class RustGenerator : public BaseGenerator { code_ += ""; code_ += "impl ::flatbuffers::EndianScalar for {{ENUM_TY}} {"; code_ += " type Scalar = {{BASE_TYPE}};"; + code_ += ""; code_ += " #[inline]"; code_ += " fn to_little_endian(self) -> {{BASE_TYPE}} {"; code_ += " {{INTO_BASE}}.to_le()"; code_ += " }"; + code_ += ""; code_ += " #[inline]"; code_ += " #[allow(clippy::wrong_self_convention)]"; code_ += " fn from_little_endian(v: {{BASE_TYPE}}) -> Self {"; @@ -922,8 +939,8 @@ class RustGenerator : public BaseGenerator { if (enum_def.is_union) { // Generate typesafe offset(s) for unions code_.SetValue("UNION_TYPE", namer_.Type(enum_def)); - code_ += "{{ACCESS_TYPE}} struct {{UNION_TYPE}}UnionTableOffset {}"; code_ += ""; + code_ += "{{ACCESS_TYPE}} struct {{UNION_TYPE}}UnionTableOffset {}"; if (parser_.opts.generate_object_based_api) { GenUnionObject(enum_def); } @@ -955,6 +972,7 @@ class RustGenerator : public BaseGenerator { code_.SetValue("ENUM_OTY", namer_.ObjectType(enum_def)); // Generate native union. + code_ += ""; code_ += "#[allow(clippy::upper_case_acronyms)]"; // NONE's spelling is // intended. code_ += "#[non_exhaustive]"; @@ -966,12 +984,15 @@ class RustGenerator : public BaseGenerator { "{{NATIVE_VARIANT}}(alloc::boxed::Box<{{U_ELEMENT_TABLE_TYPE}}>),"; }); code_ += "}"; + code_ += ""; + // Generate Default (NONE). code_ += "impl Default for {{ENUM_OTY}} {"; code_ += " fn default() -> Self {"; code_ += " Self::NONE"; code_ += " }"; code_ += "}"; + code_ += ""; // Generate native union methods. code_ += "impl {{ENUM_OTY}} {"; @@ -988,6 +1009,8 @@ class RustGenerator : public BaseGenerator { }); code_ += " }"; code_ += " }"; + code_ += ""; + // Pack flatbuffers union value code_ += " pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut " @@ -1006,6 +1029,7 @@ class RustGenerator : public BaseGenerator { // Generate some accessors; ForAllUnionObjectVariantsBesidesNone(enum_def, [&] { // Move accessor. + code_ += ""; code_ += "/// If the union variant matches, return the owned " "{{U_ELEMENT_TABLE_TYPE}}, setting the union to NONE."; @@ -1023,7 +1047,9 @@ class RustGenerator : public BaseGenerator { code_ += " None"; code_ += " }"; code_ += "}"; + // Immutable reference accessor. + code_ += ""; code_ += "/// If the union variant matches, return a reference to the " "{{U_ELEMENT_TABLE_TYPE}}."; @@ -1034,7 +1060,9 @@ class RustGenerator : public BaseGenerator { " if let Self::{{NATIVE_VARIANT}}(v) = self " "{ Some(v.as_ref()) } else { None }"; code_ += "}"; + // Mutable reference accessor. + code_ += ""; code_ += "/// If the union variant matches, return a mutable reference" " to the {{U_ELEMENT_TABLE_TYPE}}."; @@ -1046,7 +1074,9 @@ class RustGenerator : public BaseGenerator { "{ Some(v.as_mut()) } else { None }"; code_ += "}"; }); + code_ += "}"; // End union methods impl. + code_ += ""; } enum DefaultContext { kBuilder, kAccessor, kObject }; @@ -1673,6 +1703,8 @@ class RustGenerator : public BaseGenerator { // Generate an accessor struct, builder struct, and create function for a // table. void GenTable(const StructDef& struct_def) { + code_ += ""; + const bool is_private = parser_.opts.no_leak_private_annotations && (struct_def.attributes.Lookup("private") != nullptr); @@ -1683,17 +1715,18 @@ class RustGenerator : public BaseGenerator { // Generate an offset type, the base type, the Follow impl, and the // init_from_table impl. code_ += "{{ACCESS_TYPE}} enum {{STRUCT_TY}}Offset {}"; - code_ += "#[derive(Copy, Clone, PartialEq)]"; code_ += ""; GenComment(struct_def.doc_comment); + code_ += "#[derive(Copy, Clone, PartialEq)]"; code_ += "{{ACCESS_TYPE}} struct {{STRUCT_TY}}<'a> {"; code_ += " pub _tab: ::flatbuffers::Table<'a>,"; code_ += "}"; code_ += ""; code_ += "impl<'a> ::flatbuffers::Follow<'a> for {{STRUCT_TY}}<'a> {"; code_ += " type Inner = {{STRUCT_TY}}<'a>;"; + code_ += ""; code_ += " #[inline]"; code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {"; code_ += @@ -1710,7 +1743,8 @@ class RustGenerator : public BaseGenerator { "pub const {{OFFSET_NAME}}: ::flatbuffers::VOffsetT = " "{{OFFSET_VALUE}};"; }); - code_ += ""; + + if (struct_def.fields.vec.size() > 0) { code_ += ""; } if (parser_.opts.generate_name_strings) { GenFullyQualifiedNameGetter(struct_def, struct_def.name); @@ -1722,6 +1756,7 @@ class RustGenerator : public BaseGenerator { "Self {"; code_ += " {{STRUCT_TY}} { _tab: table }"; code_ += " }"; + code_ += ""; // Generate a convenient create* function that uses the above builder // to create a table in one function call. @@ -1759,6 +1794,7 @@ class RustGenerator : public BaseGenerator { code_ += " builder.finish()"; code_ += " }"; code_ += ""; + // Generate Object API Packer function. if (parser_.opts.generate_object_based_api) { // TODO(cneo): Replace more for loops with ForAllX stuff. @@ -1858,6 +1894,7 @@ class RustGenerator : public BaseGenerator { code_ += " };"; } }); + code_ += " {{STRUCT_OTY}} {"; ForAllObjectTableFields(struct_def, [&](const FieldDef& field) { if (field.value.type.base_type == BASE_TYPE_UTYPE) return; @@ -1867,8 +1904,6 @@ class RustGenerator : public BaseGenerator { code_ += " }"; } - if (struct_def.fields.vec.size() > 0) code_ += ""; - // Generate the accessors. Each has one of two forms: // // If a value can be None: @@ -1881,6 +1916,7 @@ class RustGenerator : public BaseGenerator { // self._tab.get::(offset, defaultval).unwrap() // } ForAllTableFields(struct_def, [&](const FieldDef& field) { + code_ += ""; code_.SetValue("RETURN_TYPE", GenTableAccessorFuncReturnType(field, "'a")); @@ -1911,6 +1947,7 @@ class RustGenerator : public BaseGenerator { FLATBUFFERS_ASSERT(nested_root); // Guaranteed to exist by parser. code_.SetValue("NESTED", WrapInNameSpace(*nested_root)); + code_ += ""; code_ += "pub fn {{FIELD}}_nested_flatbuffer(&'a self) -> \\"; if (field.IsRequired()) { code_ += "{{NESTED}}<'a> {"; @@ -1944,6 +1981,7 @@ class RustGenerator : public BaseGenerator { ForAllUnionVariantsBesidesNone( *field.value.type.enum_def, [&](const EnumVal& unused) { (void)unused; + code_ += ""; code_ += "#[inline]"; code_ += "#[allow(non_snake_case)]"; code_ += @@ -1987,7 +2025,6 @@ class RustGenerator : public BaseGenerator { code_ += " None"; code_ += " }"; code_ += "}"; - code_ += ""; }); }); code_ += "}"; // End of table impl. @@ -2042,6 +2079,7 @@ class RustGenerator : public BaseGenerator { code_ += " Ok(())"; code_ += " }"; code_ += "}"; + code_ += ""; // Generate an args struct: code_.SetValue("MAYBE_LT", @@ -2052,6 +2090,7 @@ class RustGenerator : public BaseGenerator { code_ += " pub {{FIELD}}: {{PARAM_TYPE}},"; }); code_ += "}"; + code_ += ""; // Generate an impl of Default for the *Args type: code_ += "impl<'a> Default for {{STRUCT_TY}}Args{{MAYBE_LT}} {"; @@ -2145,6 +2184,7 @@ class RustGenerator : public BaseGenerator { " start_: ::flatbuffers::WIPOffset<" "::flatbuffers::TableUnfinishedWIPOffset>,"; code_ += "}"; + code_ += ""; // Generate builder functions: code_ += @@ -2180,6 +2220,7 @@ class RustGenerator : public BaseGenerator { code_ += " {{FUNC_BODY}}({{FIELD_OFFSET}}, {{FIELD}});"; } code_ += "}"; + code_ += ""; }); // Struct initializer (all fields required); @@ -2195,6 +2236,7 @@ class RustGenerator : public BaseGenerator { code_ += " start_: start,"; code_ += " }"; code_ += " }"; + code_ += ""; // finish() function. code_ += " #[inline]"; @@ -2258,6 +2300,8 @@ class RustGenerator : public BaseGenerator { } void GenTableObject(const StructDef& table) { + code_ += ""; + code_.SetValue("STRUCT_OTY", namer_.ObjectType(table)); code_.SetValue("STRUCT_TY", namer_.Type(table)); @@ -2272,6 +2316,7 @@ class RustGenerator : public BaseGenerator { code_ += "pub {{FIELD}}: {{FIELD_OTY}},"; }); code_ += "}"; + code_ += ""; code_ += "impl Default for {{STRUCT_OTY}} {"; code_ += " fn default() -> Self {"; @@ -2284,6 +2329,7 @@ class RustGenerator : public BaseGenerator { code_ += " }"; code_ += " }"; code_ += "}"; + code_ += ""; // TODO(cneo): Generate defaults for Native tables. However, since structs // may be required, they, and therefore enums need defaults. @@ -2430,6 +2476,8 @@ class RustGenerator : public BaseGenerator { code_.SetValue("KEY_TYPE", GenTableAccessorFuncReturnType(field, "")); code_.SetValue("REF", IsString(field.value.type) ? "" : "&"); + code_ += ""; + code_ += "#[inline]"; code_ += "pub fn key_compare_less_than(&self, o: &{{STRUCT_TY}}) -> " @@ -2437,6 +2485,7 @@ class RustGenerator : public BaseGenerator { code_ += " self.{{FIELD}}() < o.{{FIELD}}()"; code_ += "}"; code_ += ""; + code_ += "#[inline]"; code_ += "pub fn key_compare_with_value(&self, val: {{KEY_TYPE}}) -> " @@ -2449,45 +2498,51 @@ class RustGenerator : public BaseGenerator { // Generate functions for accessing the root table object. This function // must only be called if the root table is defined. void GenRootTableFuncs(const StructDef& struct_def) { + code_ += ""; + FLATBUFFERS_ASSERT(parser_.root_struct_def_ && "root table not defined"); code_.SetValue("STRUCT_TY", namer_.Type(struct_def)); code_.SetValue("STRUCT_FN", namer_.Function(struct_def)); code_.SetValue("STRUCT_CONST", namer_.Constant(struct_def.name)); // Default verifier root fns. - code_ += "#[inline]"; code_ += "/// Verifies that a buffer of bytes contains a `{{STRUCT_TY}}`"; code_ += "/// and returns it."; code_ += "/// Note that verification is still experimental and may not"; code_ += "/// catch every error, or be maximally performant. For the"; code_ += "/// previous, unchecked, behavior use"; code_ += "/// `root_as_{{STRUCT_FN}}_unchecked`."; + code_ += "#[inline]"; code_ += "pub fn root_as_{{STRUCT_FN}}(buf: &[u8]) " "-> Result<{{STRUCT_TY}}<'_>, ::flatbuffers::InvalidFlatbuffer> {"; code_ += " ::flatbuffers::root::<{{STRUCT_TY}}>(buf)"; code_ += "}"; - code_ += "#[inline]"; + code_ += ""; + code_ += "/// Verifies that a buffer of bytes contains a size prefixed"; code_ += "/// `{{STRUCT_TY}}` and returns it."; code_ += "/// Note that verification is still experimental and may not"; code_ += "/// catch every error, or be maximally performant. For the"; code_ += "/// previous, unchecked, behavior use"; code_ += "/// `size_prefixed_root_as_{{STRUCT_FN}}_unchecked`."; + code_ += "#[inline]"; code_ += "pub fn size_prefixed_root_as_{{STRUCT_FN}}" "(buf: &[u8]) -> Result<{{STRUCT_TY}}<'_>, " "::flatbuffers::InvalidFlatbuffer> {"; code_ += " ::flatbuffers::size_prefixed_root::<{{STRUCT_TY}}>(buf)"; code_ += "}"; + code_ += ""; + // Verifier with options root fns. - code_ += "#[inline]"; code_ += "/// Verifies, with the given options, that a buffer of bytes"; code_ += "/// contains a `{{STRUCT_TY}}` and returns it."; code_ += "/// Note that verification is still experimental and may not"; code_ += "/// catch every error, or be maximally performant. For the"; code_ += "/// previous, unchecked, behavior use"; code_ += "/// `root_as_{{STRUCT_FN}}_unchecked`."; + code_ += "#[inline]"; code_ += "pub fn root_as_{{STRUCT_FN}}_with_opts<'b, 'o>("; code_ += " opts: &'o ::flatbuffers::VerifierOptions,"; code_ += " buf: &'b [u8],"; @@ -2496,13 +2551,15 @@ class RustGenerator : public BaseGenerator { " {"; code_ += " ::flatbuffers::root_with_opts::<{{STRUCT_TY}}<'b>>(opts, buf)"; code_ += "}"; - code_ += "#[inline]"; + code_ += ""; + code_ += "/// Verifies, with the given verifier options, that a buffer of"; code_ += "/// bytes contains a size prefixed `{{STRUCT_TY}}` and returns"; code_ += "/// it. Note that verification is still experimental and may not"; code_ += "/// catch every error, or be maximally performant. For the"; code_ += "/// previous, unchecked, behavior use"; code_ += "/// `root_as_{{STRUCT_FN}}_unchecked`."; + code_ += "#[inline]"; code_ += "pub fn size_prefixed_root_as_{{STRUCT_FN}}_with_opts" "<'b, 'o>("; @@ -2515,8 +2572,9 @@ class RustGenerator : public BaseGenerator { " ::flatbuffers::size_prefixed_root_with_opts::<{{STRUCT_TY}}" "<'b>>(opts, buf)"; code_ += "}"; + code_ += ""; + // Unchecked root fns. - code_ += "#[inline]"; code_ += "/// Assumes, without verification, that a buffer of bytes " "contains a {{STRUCT_TY}} and returns it."; @@ -2524,12 +2582,14 @@ class RustGenerator : public BaseGenerator { code_ += "/// Callers must trust the given bytes do indeed contain a valid" " `{{STRUCT_TY}}`."; + code_ += "#[inline]"; code_ += "pub unsafe fn root_as_{{STRUCT_FN}}_unchecked" "(buf: &[u8]) -> {{STRUCT_TY}}<'_> {"; code_ += " unsafe { ::flatbuffers::root_unchecked::<{{STRUCT_TY}}>(buf) }"; code_ += "}"; - code_ += "#[inline]"; + code_ += ""; + code_ += "/// Assumes, without verification, that a buffer of bytes " "contains a size prefixed {{STRUCT_TY}} and returns it."; @@ -2537,6 +2597,7 @@ class RustGenerator : public BaseGenerator { code_ += "/// Callers must trust the given bytes do indeed contain a valid" " size prefixed `{{STRUCT_TY}}`."; + code_ += "#[inline]"; code_ += "pub unsafe fn size_prefixed_root_as_{{STRUCT_FN}}" "_unchecked(buf: &[u8]) -> {{STRUCT_TY}}<'_> {"; @@ -2545,6 +2606,7 @@ class RustGenerator : public BaseGenerator { "::flatbuffers::size_prefixed_root_unchecked::<{{STRUCT_TY}}>" "(buf) }"; code_ += "}"; + code_ += ""; if (parser_.file_identifier_.length()) { // Declare the identifier @@ -2652,6 +2714,8 @@ class RustGenerator : public BaseGenerator { } // Generate an accessor struct with constructor for a flatbuffers struct. void GenStruct(const StructDef& struct_def) { + code_ += ""; + const bool is_private = parser_.opts.no_leak_private_annotations && (struct_def.attributes.Lookup("private") != nullptr); @@ -2674,11 +2738,14 @@ class RustGenerator : public BaseGenerator { code_ += "#[repr(transparent)]"; code_ += "#[derive(Clone, Copy, PartialEq)]"; code_ += "{{ACCESS_TYPE}} struct {{STRUCT_TY}}(pub [u8; {{STRUCT_SIZE}}]);"; + code_ += ""; + code_ += "impl Default for {{STRUCT_TY}} { "; code_ += " fn default() -> Self { "; code_ += " Self([0; {{STRUCT_SIZE}}])"; code_ += " }"; code_ += "}"; + code_ += ""; // Debug for structs. code_ += "impl ::core::fmt::Debug for {{STRUCT_TY}} {"; @@ -2699,15 +2766,21 @@ class RustGenerator : public BaseGenerator { // Follow for the value type, Follow for the reference type, Push for the // value type, and Push for the reference type. code_ += "impl ::flatbuffers::SimpleToVerifyInSlice for {{STRUCT_TY}} {}"; + code_ += ""; + code_ += "impl<'a> ::flatbuffers::Follow<'a> for {{STRUCT_TY}} {"; code_ += " type Inner = &'a {{STRUCT_TY}};"; + code_ += ""; code_ += " #[inline]"; code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {"; code_ += " unsafe { <&'a {{STRUCT_TY}}>::follow(buf, loc) }"; code_ += " }"; code_ += "}"; + code_ += ""; + code_ += "impl<'a> ::flatbuffers::Follow<'a> for &'a {{STRUCT_TY}} {"; code_ += " type Inner = &'a {{STRUCT_TY}};"; + code_ += ""; code_ += " #[inline]"; code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {"; code_ += @@ -2715,8 +2788,11 @@ class RustGenerator : public BaseGenerator { "loc) }"; code_ += " }"; code_ += "}"; + code_ += ""; + code_ += "impl<'b> ::flatbuffers::Push for {{STRUCT_TY}} {"; code_ += " type Output = {{STRUCT_TY}};"; + code_ += ""; code_ += " #[inline]"; code_ += " unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {"; code_ += @@ -2725,6 +2801,8 @@ class RustGenerator : public BaseGenerator { "{{STRUCT_TY}} as *const u8, ::size()) };"; code_ += " dst.copy_from_slice(src);"; code_ += " }"; + code_ += ""; + code_ += " #[inline]"; code_ += " fn alignment() -> ::flatbuffers::PushAlignment {"; code_ += " ::flatbuffers::PushAlignment::new({{ALIGN}})"; @@ -2934,11 +3012,11 @@ class RustGenerator : public BaseGenerator { } code_ += "}"; // End impl Struct methods. - code_ += ""; // Generate Struct Object. if (parser_.opts.generate_object_based_api) { // Struct declaration + code_ += ""; code_ += "#[derive(Debug, Clone, PartialEq, Default)]"; code_ += "{{ACCESS_TYPE}} struct {{STRUCT_OTY}} {"; ForAllStructFields(struct_def, [&](const FieldDef& field) { @@ -2946,6 +3024,8 @@ class RustGenerator : public BaseGenerator { code_ += "pub {{FIELD}}: {{FIELD_OTY}},"; }); code_ += "}"; + code_ += ""; + // The `pack` method that turns the native struct into its Flatbuffers // counterpart. code_ += "impl {{STRUCT_OTY}} {"; @@ -2969,16 +3049,13 @@ class RustGenerator : public BaseGenerator { code_ += " )"; code_ += " }"; code_ += "}"; - code_ += ""; } } - void GenNamespaceImports(const int white_spaces) { + void GenNamespaceImports() { // DO not use global attributes (i.e. #![...]) since it interferes // with users who include! generated files. // See: https://github.com/google/flatbuffers/issues/6261 - std::string indent = std::string(white_spaces, ' '); - code_ += ""; if (!parser_.opts.generate_all) { for (auto it = parser_.included_files_.begin(); it != parser_.included_files_.end(); ++it) { @@ -2987,23 +3064,22 @@ class RustGenerator : public BaseGenerator { auto basename = flatbuffers::StripPath(noext); if (parser_.opts.include_prefix.empty()) { - code_ += indent + "use crate::" + basename + - parser_.opts.filename_suffix + "::*;"; + code_ += + "use crate::" + basename + parser_.opts.filename_suffix + "::*;"; } else { auto prefix = parser_.opts.include_prefix; prefix.pop_back(); - code_ += indent + "use crate::" + prefix + "::" + basename + + code_ += "use crate::" + prefix + "::" + basename + parser_.opts.filename_suffix + "::*;"; } } } + if (parser_.opts.rust_serialize) { - code_ += indent + "extern crate serde;"; + code_ += "extern crate serde;"; code_ += - indent + "use self::serde::ser::{Serialize, Serializer, SerializeStruct};"; - code_ += ""; } code_ += "extern crate alloc;"; } @@ -3036,22 +3112,18 @@ class RustGenerator : public BaseGenerator { // Close cur_name_space in reverse order to reach the common prefix. // In the previous example, D then C are closed. for (size_t j = old_size; j > common_prefix_size; --j) { - code_ += "} // pub mod " + cur_name_space_->components[j - 1]; - } - if (old_size != common_prefix_size) { - code_ += ""; + code_.DecrementIdentLevel(); + code_ += "} // pub mod " + cur_name_space_->components[j - 1]; } // open namespace parts to reach the ns namespace // in the previous example, E, then F, then G are opened for (auto j = common_prefix_size; j != new_size; ++j) { + code_ += ""; code_ += "#[allow(unused_imports, dead_code)]"; code_ += "pub mod " + namer_.Namespace(ns->components[j]) + " {"; - // Generate local namespace imports. - GenNamespaceImports(2); - } - if (new_size != common_prefix_size) { - code_ += ""; + code_.IncrementIdentLevel(); + GenNamespaceImports(); } cur_name_space_ = ns; From 330d92de2fb9afad984739adf208ca9f823254c6 Mon Sep 17 00:00:00 2001 From: Cameron Mulhern Date: Mon, 22 Dec 2025 14:30:00 -0500 Subject: [PATCH 2/2] Regenerates generated schemas --- goldens/rust/basic_generated.rs | 577 ++++++++-------- .../my_game/sample/color_generated.rs | 11 + .../my_game/sample/equipment_generated.rs | 19 + .../my_game/sample/monster_generated.rs | 52 +- .../my_game/sample/vec_3_generated.rs | 12 +- .../my_game/sample/weapon_generated.rs | 15 +- .../my_game/example/array_struct_generated.rs | 12 +- .../my_game/example/array_table_generated.rs | 32 +- .../example/nested_struct_generated.rs | 12 +- .../my_game/example/test_enum_generated.rs | 11 + .../from_include_generated.rs | 11 + .../other_name_space/table_b_generated.rs | 13 +- .../other_name_space/unused_generated.rs | 12 +- tests/include_test1/table_a_generated.rs | 13 +- tests/include_test1_generated.rs | 641 ++++++++++-------- .../from_include_generated.rs | 11 + .../other_name_space/table_b_generated.rs | 13 +- .../other_name_space/unused_generated.rs | 12 +- tests/include_test2/table_a_generated.rs | 13 +- tests/include_test2_generated.rs | 641 ++++++++++-------- .../keyword_test/abc_generated.rs | 11 + .../keywords_in_table_generated.rs | 19 +- .../keywords_in_union_generated.rs | 22 + .../keyword_test/public_generated.rs | 11 + .../keyword_test/table_2_generated.rs | 17 +- .../my_game/example/ability_generated.rs | 13 +- .../any_ambiguous_aliases_generated.rs | 25 + .../my_game/example/any_generated.rs | 25 + .../example/any_unique_aliases_generated.rs | 25 + .../my_game/example/color_generated.rs | 6 + .../my_game/example/long_enum_generated.rs | 6 + .../my_game/example/monster_generated.rs | 157 ++++- .../my_game/example/race_generated.rs | 11 + .../my_game/example/referrable_generated.rs | 14 +- .../my_game/example/stat_generated.rs | 18 +- .../example/struct_of_structs_generated.rs | 12 +- .../struct_of_structs_of_structs_generated.rs | 12 +- .../my_game/example/test_generated.rs | 12 +- .../test_simple_table_with_enum_generated.rs | 13 +- .../my_game/example/type_aliases_generated.rs | 35 +- .../my_game/example/vec_3_generated.rs | 12 +- .../my_game/example_2/monster_generated.rs | 13 +- .../my_game/in_parent_namespace_generated.rs | 13 +- .../from_include_generated.rs | 11 + .../other_name_space/table_b_generated.rs | 13 +- .../other_name_space/unused_generated.rs | 12 +- tests/monster_test/table_a_generated.rs | 13 +- .../my_game/example/ability_generated.rs | 13 +- .../any_ambiguous_aliases_generated.rs | 25 + .../my_game/example/any_generated.rs | 25 + .../example/any_unique_aliases_generated.rs | 25 + .../my_game/example/color_generated.rs | 6 + .../my_game/example/long_enum_generated.rs | 6 + .../my_game/example/monster_generated.rs | 157 ++++- .../my_game/example/race_generated.rs | 11 + .../my_game/example/referrable_generated.rs | 14 +- .../my_game/example/stat_generated.rs | 18 +- .../example/struct_of_structs_generated.rs | 12 +- .../struct_of_structs_of_structs_generated.rs | 12 +- .../my_game/example/test_generated.rs | 12 +- .../test_simple_table_with_enum_generated.rs | 13 +- .../my_game/example/type_aliases_generated.rs | 35 +- .../my_game/example/vec_3_generated.rs | 12 +- .../my_game/example_2/monster_generated.rs | 13 +- .../my_game/in_parent_namespace_generated.rs | 13 +- .../from_include_generated.rs | 11 + .../other_name_space/table_b_generated.rs | 13 +- .../other_name_space/unused_generated.rs | 12 +- .../table_a_generated.rs | 13 +- tests/more_defaults/abc_generated.rs | 11 + .../more_defaults/more_defaults_generated.rs | 23 +- .../enum_in_nested_ns_generated.rs | 11 + .../struct_in_nested_ns_generated.rs | 12 +- .../table_in_nested_ns_generated.rs | 13 +- .../union_in_nested_ns_generated.rs | 19 + .../second_table_in_a_generated.rs | 13 +- .../table_in_first_ns_generated.rs | 23 +- .../namespace_c/table_in_c_generated.rs | 15 +- .../optional_byte_generated.rs | 11 + .../scalar_stuff_generated.rs | 102 ++- tests/private_annotation_test/ab_generated.rs | 11 + .../annotations_generated.rs | 13 +- .../private_annotation_test/any_generated.rs | 22 + .../private_annotation_test/game_generated.rs | 13 +- .../object_generated.rs | 12 +- .../rust_namer_test/field_table_generated.rs | 13 +- .../rust_namer_test/field_union_generated.rs | 19 + .../rust_namer_test/game_message_generated.rs | 25 + .../game_message_wrapper_generated.rs | 17 +- .../player_input_change_generated.rs | 13 +- .../player_spectate_generated.rs | 13 +- .../player_stat_event_generated.rs | 13 +- .../possibly_reserved_words_generated.rs | 12 +- .../rust_namer_test/root_table_generated.rs | 17 +- 94 files changed, 2635 insertions(+), 986 deletions(-) diff --git a/goldens/rust/basic_generated.rs b/goldens/rust/basic_generated.rs index aa251d1c097..941408d4a37 100644 --- a/goldens/rust/basic_generated.rs +++ b/goldens/rust/basic_generated.rs @@ -1,297 +1,318 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated - extern crate alloc; #[allow(unused_imports, dead_code)] pub mod flatbuffers { + extern crate alloc; -extern crate alloc; -#[allow(unused_imports, dead_code)] -pub mod goldens { + #[allow(unused_imports, dead_code)] + pub mod goldens { + extern crate alloc; -extern crate alloc; + pub enum GalaxyOffset {} + + #[derive(Copy, Clone, PartialEq)] + pub struct Galaxy<'a> { + pub _tab: ::flatbuffers::Table<'a>, + } + + impl<'a> ::flatbuffers::Follow<'a> for Galaxy<'a> { + type Inner = Galaxy<'a>; + + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } + } + } -pub enum GalaxyOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct Galaxy<'a> { - pub _tab: ::flatbuffers::Table<'a>, -} - -impl<'a> ::flatbuffers::Follow<'a> for Galaxy<'a> { - type Inner = Galaxy<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } - } -} - -impl<'a> Galaxy<'a> { - pub const VT_NUM_STARS: ::flatbuffers::VOffsetT = 4; - - #[inline] - pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { - Galaxy { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args GalaxyArgs - ) -> ::flatbuffers::WIPOffset> { - let mut builder = GalaxyBuilder::new(_fbb); - builder.add_num_stars(args.num_stars); - builder.finish() - } - - - #[inline] - pub fn num_stars(&self) -> i64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Galaxy::VT_NUM_STARS, Some(0)).unwrap()} - } -} - -impl ::flatbuffers::Verifiable for Galaxy<'_> { - #[inline] - fn run_verifier( - v: &mut ::flatbuffers::Verifier, pos: usize - ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { - v.visit_table(pos)? + impl<'a> Galaxy<'a> { + pub const VT_NUM_STARS: ::flatbuffers::VOffsetT = 4; + + #[inline] + pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { + Galaxy { _tab: table } + } + + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args GalaxyArgs + ) -> ::flatbuffers::WIPOffset> { + let mut builder = GalaxyBuilder::new(_fbb); + builder.add_num_stars(args.num_stars); + builder.finish() + } + + + #[inline] + pub fn num_stars(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Galaxy::VT_NUM_STARS, Some(0)).unwrap()} + } + } + + impl ::flatbuffers::Verifiable for Galaxy<'_> { + #[inline] + fn run_verifier( + v: &mut ::flatbuffers::Verifier, pos: usize + ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? .visit_field::("num_stars", Self::VT_NUM_STARS, false)? .finish(); - Ok(()) - } -} -pub struct GalaxyArgs { - pub num_stars: i64, -} -impl<'a> Default for GalaxyArgs { - #[inline] - fn default() -> Self { - GalaxyArgs { - num_stars: 0, + Ok(()) + } + } + + pub struct GalaxyArgs { + pub num_stars: i64, } - } -} - -pub struct GalaxyBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { - fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, - start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, -} -impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> GalaxyBuilder<'a, 'b, A> { - #[inline] - pub fn add_num_stars(&mut self, num_stars: i64) { - self.fbb_.push_slot::(Galaxy::VT_NUM_STARS, num_stars, 0); - } - #[inline] - pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> GalaxyBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - GalaxyBuilder { - fbb_: _fbb, - start_: start, + + impl<'a> Default for GalaxyArgs { + #[inline] + fn default() -> Self { + GalaxyArgs { + num_stars: 0, + } + } + } + + pub struct GalaxyBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { + fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, + start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, + } + + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> GalaxyBuilder<'a, 'b, A> { + #[inline] + pub fn add_num_stars(&mut self, num_stars: i64) { + self.fbb_.push_slot::(Galaxy::VT_NUM_STARS, num_stars, 0); + } + + #[inline] + pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> GalaxyBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + GalaxyBuilder { + fbb_: _fbb, + start_: start, + } + } + + #[inline] + pub fn finish(self) -> ::flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + ::flatbuffers::WIPOffset::new(o.value()) + } + } + + impl ::core::fmt::Debug for Galaxy<'_> { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + let mut ds = f.debug_struct("Galaxy"); + ds.field("num_stars", &self.num_stars()); + ds.finish() + } } - } - #[inline] - pub fn finish(self) -> ::flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - ::flatbuffers::WIPOffset::new(o.value()) - } -} - -impl ::core::fmt::Debug for Galaxy<'_> { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - let mut ds = f.debug_struct("Galaxy"); - ds.field("num_stars", &self.num_stars()); - ds.finish() - } -} -pub enum UniverseOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct Universe<'a> { - pub _tab: ::flatbuffers::Table<'a>, -} - -impl<'a> ::flatbuffers::Follow<'a> for Universe<'a> { - type Inner = Universe<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } - } -} - -impl<'a> Universe<'a> { - pub const VT_AGE: ::flatbuffers::VOffsetT = 4; - pub const VT_GALAXIES: ::flatbuffers::VOffsetT = 6; - - #[inline] - pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { - Universe { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args UniverseArgs<'args> - ) -> ::flatbuffers::WIPOffset> { - let mut builder = UniverseBuilder::new(_fbb); - builder.add_age(args.age); - if let Some(x) = args.galaxies { builder.add_galaxies(x); } - builder.finish() - } - - - #[inline] - pub fn age(&self) -> f64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Universe::VT_AGE, Some(0.0)).unwrap()} - } - #[inline] - pub fn galaxies(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Universe::VT_GALAXIES, None)} - } -} - -impl ::flatbuffers::Verifiable for Universe<'_> { - #[inline] - fn run_verifier( - v: &mut ::flatbuffers::Verifier, pos: usize - ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { - v.visit_table(pos)? + + pub enum UniverseOffset {} + + #[derive(Copy, Clone, PartialEq)] + pub struct Universe<'a> { + pub _tab: ::flatbuffers::Table<'a>, + } + + impl<'a> ::flatbuffers::Follow<'a> for Universe<'a> { + type Inner = Universe<'a>; + + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } + } + } + + impl<'a> Universe<'a> { + pub const VT_AGE: ::flatbuffers::VOffsetT = 4; + pub const VT_GALAXIES: ::flatbuffers::VOffsetT = 6; + + #[inline] + pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { + Universe { _tab: table } + } + + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args UniverseArgs<'args> + ) -> ::flatbuffers::WIPOffset> { + let mut builder = UniverseBuilder::new(_fbb); + builder.add_age(args.age); + if let Some(x) = args.galaxies { builder.add_galaxies(x); } + builder.finish() + } + + + #[inline] + pub fn age(&self) -> f64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Universe::VT_AGE, Some(0.0)).unwrap()} + } + + #[inline] + pub fn galaxies(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Universe::VT_GALAXIES, None)} + } + } + + impl ::flatbuffers::Verifiable for Universe<'_> { + #[inline] + fn run_verifier( + v: &mut ::flatbuffers::Verifier, pos: usize + ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? .visit_field::("age", Self::VT_AGE, false)? .visit_field::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'_, ::flatbuffers::ForwardsUOffset>>>("galaxies", Self::VT_GALAXIES, false)? .finish(); - Ok(()) - } -} -pub struct UniverseArgs<'a> { - pub age: f64, - pub galaxies: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>>, -} -impl<'a> Default for UniverseArgs<'a> { - #[inline] - fn default() -> Self { - UniverseArgs { - age: 0.0, - galaxies: None, + Ok(()) + } + } + + pub struct UniverseArgs<'a> { + pub age: f64, + pub galaxies: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>>, } - } -} - -pub struct UniverseBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { - fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, - start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, -} -impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> UniverseBuilder<'a, 'b, A> { - #[inline] - pub fn add_age(&mut self, age: f64) { - self.fbb_.push_slot::(Universe::VT_AGE, age, 0.0); - } - #[inline] - pub fn add_galaxies(&mut self, galaxies: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { - self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Universe::VT_GALAXIES, galaxies); - } - #[inline] - pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> UniverseBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - UniverseBuilder { - fbb_: _fbb, - start_: start, + + impl<'a> Default for UniverseArgs<'a> { + #[inline] + fn default() -> Self { + UniverseArgs { + age: 0.0, + galaxies: None, + } + } } - } - #[inline] - pub fn finish(self) -> ::flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - ::flatbuffers::WIPOffset::new(o.value()) - } -} - -impl ::core::fmt::Debug for Universe<'_> { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - let mut ds = f.debug_struct("Universe"); - ds.field("age", &self.age()); - ds.field("galaxies", &self.galaxies()); - ds.finish() - } -} -#[inline] -/// Verifies that a buffer of bytes contains a `Universe` -/// and returns it. -/// Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `root_as_universe_unchecked`. -pub fn root_as_universe(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { - ::flatbuffers::root::(buf) -} -#[inline] -/// Verifies that a buffer of bytes contains a size prefixed -/// `Universe` and returns it. -/// Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `size_prefixed_root_as_universe_unchecked`. -pub fn size_prefixed_root_as_universe(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { - ::flatbuffers::size_prefixed_root::(buf) -} -#[inline] -/// Verifies, with the given options, that a buffer of bytes -/// contains a `Universe` and returns it. -/// Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `root_as_universe_unchecked`. -pub fn root_as_universe_with_opts<'b, 'o>( - opts: &'o ::flatbuffers::VerifierOptions, - buf: &'b [u8], -) -> Result, ::flatbuffers::InvalidFlatbuffer> { - ::flatbuffers::root_with_opts::>(opts, buf) -} -#[inline] -/// Verifies, with the given verifier options, that a buffer of -/// bytes contains a size prefixed `Universe` and returns -/// it. Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `root_as_universe_unchecked`. -pub fn size_prefixed_root_as_universe_with_opts<'b, 'o>( - opts: &'o ::flatbuffers::VerifierOptions, - buf: &'b [u8], -) -> Result, ::flatbuffers::InvalidFlatbuffer> { - ::flatbuffers::size_prefixed_root_with_opts::>(opts, buf) -} -#[inline] -/// Assumes, without verification, that a buffer of bytes contains a Universe and returns it. -/// # Safety -/// Callers must trust the given bytes do indeed contain a valid `Universe`. -pub unsafe fn root_as_universe_unchecked(buf: &[u8]) -> Universe<'_> { - unsafe { ::flatbuffers::root_unchecked::(buf) } -} -#[inline] -/// Assumes, without verification, that a buffer of bytes contains a size prefixed Universe and returns it. -/// # Safety -/// Callers must trust the given bytes do indeed contain a valid size prefixed `Universe`. -pub unsafe fn size_prefixed_root_as_universe_unchecked(buf: &[u8]) -> Universe<'_> { - unsafe { ::flatbuffers::size_prefixed_root_unchecked::(buf) } -} -#[inline] -pub fn finish_universe_buffer<'a, 'b, A: ::flatbuffers::Allocator + 'a>( - fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, - root: ::flatbuffers::WIPOffset>) { - fbb.finish(root, None); -} - -#[inline] -pub fn finish_size_prefixed_universe_buffer<'a, 'b, A: ::flatbuffers::Allocator + 'a>(fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, root: ::flatbuffers::WIPOffset>) { - fbb.finish_size_prefixed(root, None); -} -} // pub mod goldens -} // pub mod flatbuffers + pub struct UniverseBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { + fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, + start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, + } + + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> UniverseBuilder<'a, 'b, A> { + #[inline] + pub fn add_age(&mut self, age: f64) { + self.fbb_.push_slot::(Universe::VT_AGE, age, 0.0); + } + + #[inline] + pub fn add_galaxies(&mut self, galaxies: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { + self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Universe::VT_GALAXIES, galaxies); + } + + #[inline] + pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> UniverseBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + UniverseBuilder { + fbb_: _fbb, + start_: start, + } + } + + #[inline] + pub fn finish(self) -> ::flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + ::flatbuffers::WIPOffset::new(o.value()) + } + } + + impl ::core::fmt::Debug for Universe<'_> { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + let mut ds = f.debug_struct("Universe"); + ds.field("age", &self.age()); + ds.field("galaxies", &self.galaxies()); + ds.finish() + } + } + + /// Verifies that a buffer of bytes contains a `Universe` + /// and returns it. + /// Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `root_as_universe_unchecked`. + #[inline] + pub fn root_as_universe(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { + ::flatbuffers::root::(buf) + } + + /// Verifies that a buffer of bytes contains a size prefixed + /// `Universe` and returns it. + /// Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `size_prefixed_root_as_universe_unchecked`. + #[inline] + pub fn size_prefixed_root_as_universe(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { + ::flatbuffers::size_prefixed_root::(buf) + } + + /// Verifies, with the given options, that a buffer of bytes + /// contains a `Universe` and returns it. + /// Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `root_as_universe_unchecked`. + #[inline] + pub fn root_as_universe_with_opts<'b, 'o>( + opts: &'o ::flatbuffers::VerifierOptions, + buf: &'b [u8], + ) -> Result, ::flatbuffers::InvalidFlatbuffer> { + ::flatbuffers::root_with_opts::>(opts, buf) + } + + /// Verifies, with the given verifier options, that a buffer of + /// bytes contains a size prefixed `Universe` and returns + /// it. Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `root_as_universe_unchecked`. + #[inline] + pub fn size_prefixed_root_as_universe_with_opts<'b, 'o>( + opts: &'o ::flatbuffers::VerifierOptions, + buf: &'b [u8], + ) -> Result, ::flatbuffers::InvalidFlatbuffer> { + ::flatbuffers::size_prefixed_root_with_opts::>(opts, buf) + } + + /// Assumes, without verification, that a buffer of bytes contains a Universe and returns it. + /// # Safety + /// Callers must trust the given bytes do indeed contain a valid `Universe`. + #[inline] + pub unsafe fn root_as_universe_unchecked(buf: &[u8]) -> Universe<'_> { + unsafe { ::flatbuffers::root_unchecked::(buf) } + } + + /// Assumes, without verification, that a buffer of bytes contains a size prefixed Universe and returns it. + /// # Safety + /// Callers must trust the given bytes do indeed contain a valid size prefixed `Universe`. + #[inline] + pub unsafe fn size_prefixed_root_as_universe_unchecked(buf: &[u8]) -> Universe<'_> { + unsafe { ::flatbuffers::size_prefixed_root_unchecked::(buf) } + } + + #[inline] + pub fn finish_universe_buffer<'a, 'b, A: ::flatbuffers::Allocator + 'a>( + fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, + root: ::flatbuffers::WIPOffset>) { + fbb.finish(root, None); + } + + #[inline] + pub fn finish_size_prefixed_universe_buffer<'a, 'b, A: ::flatbuffers::Allocator + 'a>(fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, root: ::flatbuffers::WIPOffset>) { + fbb.finish_size_prefixed(root, None); + } + } // pub mod goldens +} // pub mod flatbuffers diff --git a/samples/rust_generated/my_game/sample/color_generated.rs b/samples/rust_generated/my_game/sample/color_generated.rs index 34b82ac7b12..88ed9ea4484 100644 --- a/samples/rust_generated/my_game/sample/color_generated.rs +++ b/samples/rust_generated/my_game/sample/color_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_COLOR: i8 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_COLOR: [Color; 3] = [ @@ -17,6 +20,7 @@ pub const ENUM_VALUES_COLOR: [Color; 3] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Color(pub i8); + #[allow(non_upper_case_globals)] impl Color { pub const Red: Self = Self(0); @@ -30,6 +34,7 @@ impl Color { Self::Green, Self::Blue, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -40,6 +45,7 @@ impl Color { } } } + impl ::core::fmt::Debug for Color { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -49,8 +55,10 @@ impl ::core::fmt::Debug for Color { } } } + impl<'a> ::flatbuffers::Follow<'a> for Color { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -60,6 +68,7 @@ impl<'a> ::flatbuffers::Follow<'a> for Color { impl ::flatbuffers::Push for Color { type Output = Color; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -68,10 +77,12 @@ impl ::flatbuffers::Push for Color { impl ::flatbuffers::EndianScalar for Color { type Scalar = i8; + #[inline] fn to_little_endian(self) -> i8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i8) -> Self { diff --git a/samples/rust_generated/my_game/sample/equipment_generated.rs b/samples/rust_generated/my_game/sample/equipment_generated.rs index f53f8f20b05..de61cf7ec37 100644 --- a/samples/rust_generated/my_game/sample/equipment_generated.rs +++ b/samples/rust_generated/my_game/sample/equipment_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_EQUIPMENT: u8 = 1; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_EQUIPMENT: [Equipment; 2] = [ @@ -16,6 +19,7 @@ pub const ENUM_VALUES_EQUIPMENT: [Equipment; 2] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Equipment(pub u8); + #[allow(non_upper_case_globals)] impl Equipment { pub const NONE: Self = Self(0); @@ -27,6 +31,7 @@ impl Equipment { Self::NONE, Self::Weapon, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -36,6 +41,7 @@ impl Equipment { } } } + impl ::core::fmt::Debug for Equipment { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -45,8 +51,10 @@ impl ::core::fmt::Debug for Equipment { } } } + impl<'a> ::flatbuffers::Follow<'a> for Equipment { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -56,6 +64,7 @@ impl<'a> ::flatbuffers::Follow<'a> for Equipment { impl ::flatbuffers::Push for Equipment { type Output = Equipment; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -64,10 +73,12 @@ impl ::flatbuffers::Push for Equipment { impl ::flatbuffers::EndianScalar for Equipment { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -86,6 +97,7 @@ impl<'a> ::flatbuffers::Verifiable for Equipment { } impl ::flatbuffers::SimpleToVerifyInSlice for Equipment {} + pub struct EquipmentUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -95,11 +107,13 @@ pub enum EquipmentT { NONE, Weapon(alloc::boxed::Box), } + impl Default for EquipmentT { fn default() -> Self { Self::NONE } } + impl EquipmentT { pub fn equipment_type(&self) -> Equipment { match self { @@ -107,12 +121,14 @@ impl EquipmentT { Self::Weapon(_) => Equipment::Weapon, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, Self::Weapon(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned WeaponT, setting the union to NONE. pub fn take_weapon(&mut self) -> Option> { if let Self::Weapon(_) = self { @@ -126,12 +142,15 @@ impl EquipmentT { None } } + /// If the union variant matches, return a reference to the WeaponT. pub fn as_weapon(&self) -> Option<&WeaponT> { if let Self::Weapon(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the WeaponT. pub fn as_weapon_mut(&mut self) -> Option<&mut WeaponT> { if let Self::Weapon(v) = self { Some(v.as_mut()) } else { None } } } + diff --git a/samples/rust_generated/my_game/sample/monster_generated.rs b/samples/rust_generated/my_game/sample/monster_generated.rs index 381091dd721..645c1c27bac 100644 --- a/samples/rust_generated/my_game/sample/monster_generated.rs +++ b/samples/rust_generated/my_game/sample/monster_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum MonsterOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct Monster<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Monster<'a> { type Inner = Monster<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -37,6 +39,7 @@ impl<'a> Monster<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Monster { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -104,6 +107,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_POS, None)} } + #[inline] pub fn mana(&self) -> i16 { // Safety: @@ -111,6 +115,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_MANA, Some(150)).unwrap()} } + #[inline] pub fn hp(&self) -> i16 { // Safety: @@ -118,6 +123,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_HP, Some(100)).unwrap()} } + #[inline] pub fn name(&self) -> Option<&'a str> { // Safety: @@ -125,6 +131,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None)} } + #[inline] pub fn inventory(&self) -> Option<::flatbuffers::Vector<'a, u8>> { // Safety: @@ -132,6 +139,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None)} } + #[inline] pub fn color(&self) -> Color { // Safety: @@ -139,6 +147,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_COLOR, Some(Color::Blue)).unwrap()} } + #[inline] pub fn weapons(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>> { // Safety: @@ -146,6 +155,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Monster::VT_WEAPONS, None)} } + #[inline] pub fn equipped_type(&self) -> Equipment { // Safety: @@ -153,6 +163,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_EQUIPPED_TYPE, Some(Equipment::NONE)).unwrap()} } + #[inline] pub fn equipped(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -160,6 +171,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(Monster::VT_EQUIPPED, None)} } + #[inline] pub fn path(&self) -> Option<::flatbuffers::Vector<'a, Vec3>> { // Safety: @@ -167,6 +179,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, Vec3>>>(Monster::VT_PATH, None)} } + #[inline] #[allow(non_snake_case)] pub fn equipped_as_weapon(&self) -> Option> { @@ -181,7 +194,6 @@ impl<'a> Monster<'a> { None } } - } impl ::flatbuffers::Verifiable for Monster<'_> { @@ -208,6 +220,7 @@ impl ::flatbuffers::Verifiable for Monster<'_> { Ok(()) } } + pub struct MonsterArgs<'a> { pub pos: Option<&'a Vec3>, pub mana: i16, @@ -220,6 +233,7 @@ pub struct MonsterArgs<'a> { pub equipped: Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>>, pub path: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, Vec3>>>, } + impl<'a> Default for MonsterArgs<'a> { #[inline] fn default() -> Self { @@ -242,47 +256,58 @@ pub struct MonsterBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> { #[inline] pub fn add_pos(&mut self, pos: &Vec3) { self.fbb_.push_slot_always::<&Vec3>(Monster::VT_POS, pos); } + #[inline] pub fn add_mana(&mut self, mana: i16) { self.fbb_.push_slot::(Monster::VT_MANA, mana, 150); } + #[inline] pub fn add_hp(&mut self, hp: i16) { self.fbb_.push_slot::(Monster::VT_HP, hp, 100); } + #[inline] pub fn add_name(&mut self, name: ::flatbuffers::WIPOffset<&'b str>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_NAME, name); } + #[inline] pub fn add_inventory(&mut self, inventory: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_INVENTORY, inventory); } + #[inline] pub fn add_color(&mut self, color: Color) { self.fbb_.push_slot::(Monster::VT_COLOR, color, Color::Blue); } + #[inline] pub fn add_weapons(&mut self, weapons: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_WEAPONS, weapons); } + #[inline] pub fn add_equipped_type(&mut self, equipped_type: Equipment) { self.fbb_.push_slot::(Monster::VT_EQUIPPED_TYPE, equipped_type, Equipment::NONE); } + #[inline] pub fn add_equipped(&mut self, equipped: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_EQUIPPED, equipped); } + #[inline] pub fn add_path(&mut self, path: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , Vec3>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_PATH, path); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> MonsterBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -291,6 +316,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -326,6 +352,7 @@ impl ::core::fmt::Debug for Monster<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MonsterT { @@ -339,6 +366,7 @@ pub struct MonsterT { pub equipped: EquipmentT, pub path: Option>, } + impl Default for MonsterT { fn default() -> Self { Self { @@ -354,6 +382,7 @@ impl Default for MonsterT { } } } + impl MonsterT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, @@ -392,66 +421,73 @@ impl MonsterT { }) } } -#[inline] + /// Verifies that a buffer of bytes contains a `Monster` /// and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. +#[inline] pub fn root_as_monster(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::root::(buf) } -#[inline] + /// Verifies that a buffer of bytes contains a size prefixed /// `Monster` and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_monster_unchecked`. +#[inline] pub fn size_prefixed_root_as_monster(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::size_prefixed_root::(buf) } -#[inline] + /// Verifies, with the given options, that a buffer of bytes /// contains a `Monster` and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. +#[inline] pub fn root_as_monster_with_opts<'b, 'o>( opts: &'o ::flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::root_with_opts::>(opts, buf) } -#[inline] + /// Verifies, with the given verifier options, that a buffer of /// bytes contains a size prefixed `Monster` and returns /// it. Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. +#[inline] pub fn size_prefixed_root_as_monster_with_opts<'b, 'o>( opts: &'o ::flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } -#[inline] + /// Assumes, without verification, that a buffer of bytes contains a Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `Monster`. +#[inline] pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { ::flatbuffers::root_unchecked::(buf) } } -#[inline] + /// Assumes, without verification, that a buffer of bytes contains a size prefixed Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `Monster`. +#[inline] pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { ::flatbuffers::size_prefixed_root_unchecked::(buf) } } + #[inline] pub fn finish_monster_buffer<'a, 'b, A: ::flatbuffers::Allocator + 'a>( fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, 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..cc2c5c132f9 100644 --- a/samples/rust_generated/my_game/sample/vec_3_generated.rs +++ b/samples/rust_generated/my_game/sample/vec_3_generated.rs @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct Vec3, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Vec3(pub [u8; 12]); + impl Default for Vec3 { fn default() -> Self { Self([0; 12]) } } + impl ::core::fmt::Debug for Vec3 { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Vec3") @@ -22,27 +25,34 @@ impl ::core::fmt::Debug for Vec3 { } impl ::flatbuffers::SimpleToVerifyInSlice for Vec3 {} + impl<'a> ::flatbuffers::Follow<'a> for Vec3 { type Inner = &'a Vec3; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Vec3>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Vec3 { type Inner = &'a Vec3; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Vec3 { type Output = Vec3; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -178,6 +188,7 @@ pub struct Vec3T { pub y: f32, pub z: f32, } + impl Vec3T { pub fn pack(&self) -> Vec3 { Vec3::new( @@ -187,4 +198,3 @@ impl Vec3T { ) } } - diff --git a/samples/rust_generated/my_game/sample/weapon_generated.rs b/samples/rust_generated/my_game/sample/weapon_generated.rs index 7a4c2e79a7a..d11525fe6d4 100644 --- a/samples/rust_generated/my_game/sample/weapon_generated.rs +++ b/samples/rust_generated/my_game/sample/weapon_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum WeaponOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct Weapon<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Weapon<'a> { type Inner = Weapon<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -29,6 +31,7 @@ impl<'a> Weapon<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Weapon { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -58,6 +61,7 @@ impl<'a> Weapon<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<&str>>(Weapon::VT_NAME, None)} } + #[inline] pub fn damage(&self) -> i16 { // Safety: @@ -79,10 +83,12 @@ impl ::flatbuffers::Verifiable for Weapon<'_> { Ok(()) } } + pub struct WeaponArgs<'a> { pub name: Option<::flatbuffers::WIPOffset<&'a str>>, pub damage: i16, } + impl<'a> Default for WeaponArgs<'a> { #[inline] fn default() -> Self { @@ -97,15 +103,18 @@ pub struct WeaponBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> WeaponBuilder<'a, 'b, A> { #[inline] pub fn add_name(&mut self, name: ::flatbuffers::WIPOffset<&'b str>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Weapon::VT_NAME, name); } + #[inline] pub fn add_damage(&mut self, damage: i16) { self.fbb_.push_slot::(Weapon::VT_DAMAGE, damage, 0); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> WeaponBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -114,6 +123,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> WeaponBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -129,12 +139,14 @@ impl ::core::fmt::Debug for Weapon<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct WeaponT { pub name: Option, pub damage: i16, } + impl Default for WeaponT { fn default() -> Self { Self { @@ -143,6 +155,7 @@ impl Default for WeaponT { } } } + impl WeaponT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..2f446d4ebd8 100644 --- a/tests/arrays_test/my_game/example/array_struct_generated.rs +++ b/tests/arrays_test/my_game/example/array_struct_generated.rs @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct ArrayStruct, aligned to 8 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct ArrayStruct(pub [u8; 160]); + impl Default for ArrayStruct { fn default() -> Self { Self([0; 160]) } } + impl ::core::fmt::Debug for ArrayStruct { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("ArrayStruct") @@ -25,27 +28,34 @@ impl ::core::fmt::Debug for ArrayStruct { } impl ::flatbuffers::SimpleToVerifyInSlice for ArrayStruct {} + impl<'a> ::flatbuffers::Follow<'a> for ArrayStruct { type Inner = &'a ArrayStruct; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a ArrayStruct>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a ArrayStruct { type Inner = &'a ArrayStruct; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for ArrayStruct { type Output = ArrayStruct; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(8) @@ -244,6 +254,7 @@ pub struct ArrayStructT { pub e: i32, pub f: [i64; 2], } + impl ArrayStructT { pub fn pack(&self) -> ArrayStruct { ArrayStruct::new( @@ -256,4 +267,3 @@ impl ArrayStructT { ) } } - 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..449f187c203 100644 --- a/tests/arrays_test/my_game/example/array_table_generated.rs +++ b/tests/arrays_test/my_game/example/array_table_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum ArrayTableOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct ArrayTable<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for ArrayTable<'a> { type Inner = ArrayTable<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> ArrayTable<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { ArrayTable { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -67,9 +70,11 @@ impl ::flatbuffers::Verifiable for ArrayTable<'_> { Ok(()) } } + pub struct ArrayTableArgs<'a> { pub a: Option<&'a ArrayStruct>, } + impl<'a> Default for ArrayTableArgs<'a> { #[inline] fn default() -> Self { @@ -83,11 +88,13 @@ pub struct ArrayTableBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> ArrayTableBuilder<'a, 'b, A> { #[inline] pub fn add_a(&mut self, a: &ArrayStruct) { self.fbb_.push_slot_always::<&ArrayStruct>(ArrayTable::VT_A, a); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> ArrayTableBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -96,6 +103,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> ArrayTableBuilder<'a, 'b, A> start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -110,11 +118,13 @@ impl ::core::fmt::Debug for ArrayTable<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct ArrayTableT { pub a: Option, } + impl Default for ArrayTableT { fn default() -> Self { Self { @@ -122,6 +132,7 @@ impl Default for ArrayTableT { } } } + impl ArrayTableT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, @@ -134,66 +145,73 @@ impl ArrayTableT { }) } } -#[inline] + /// Verifies that a buffer of bytes contains a `ArrayTable` /// and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_array_table_unchecked`. +#[inline] pub fn root_as_array_table(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::root::(buf) } -#[inline] + /// Verifies that a buffer of bytes contains a size prefixed /// `ArrayTable` and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_array_table_unchecked`. +#[inline] pub fn size_prefixed_root_as_array_table(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::size_prefixed_root::(buf) } -#[inline] + /// Verifies, with the given options, that a buffer of bytes /// contains a `ArrayTable` and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_array_table_unchecked`. +#[inline] pub fn root_as_array_table_with_opts<'b, 'o>( opts: &'o ::flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::root_with_opts::>(opts, buf) } -#[inline] + /// Verifies, with the given verifier options, that a buffer of /// bytes contains a size prefixed `ArrayTable` and returns /// it. Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_array_table_unchecked`. +#[inline] pub fn size_prefixed_root_as_array_table_with_opts<'b, 'o>( opts: &'o ::flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } -#[inline] + /// Assumes, without verification, that a buffer of bytes contains a ArrayTable and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `ArrayTable`. +#[inline] pub unsafe fn root_as_array_table_unchecked(buf: &[u8]) -> ArrayTable<'_> { unsafe { ::flatbuffers::root_unchecked::(buf) } } -#[inline] + /// Assumes, without verification, that a buffer of bytes contains a size prefixed ArrayTable and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `ArrayTable`. +#[inline] pub unsafe fn size_prefixed_root_as_array_table_unchecked(buf: &[u8]) -> ArrayTable<'_> { unsafe { ::flatbuffers::size_prefixed_root_unchecked::(buf) } } + pub const ARRAY_TABLE_IDENTIFIER: &str = "ARRT"; #[inline] 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..40134ea51e4 100644 --- a/tests/arrays_test/my_game/example/nested_struct_generated.rs +++ b/tests/arrays_test/my_game/example/nested_struct_generated.rs @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct NestedStruct, aligned to 8 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct NestedStruct(pub [u8; 32]); + impl Default for NestedStruct { fn default() -> Self { Self([0; 32]) } } + impl ::core::fmt::Debug for NestedStruct { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("NestedStruct") @@ -23,27 +26,34 @@ impl ::core::fmt::Debug for NestedStruct { } impl ::flatbuffers::SimpleToVerifyInSlice for NestedStruct {} + impl<'a> ::flatbuffers::Follow<'a> for NestedStruct { type Inner = &'a NestedStruct; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a NestedStruct>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a NestedStruct { type Inner = &'a NestedStruct; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for NestedStruct { type Output = NestedStruct; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(8) @@ -176,6 +186,7 @@ pub struct NestedStructT { pub c: [TestEnum; 2], pub d: [i64; 2], } + impl NestedStructT { pub fn pack(&self) -> NestedStruct { NestedStruct::new( @@ -186,4 +197,3 @@ impl NestedStructT { ) } } - 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..de750a19a90 100644 --- a/tests/arrays_test/my_game/example/test_enum_generated.rs +++ b/tests/arrays_test/my_game/example/test_enum_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_TEST_ENUM: i8 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_TEST_ENUM: [TestEnum; 3] = [ @@ -17,6 +20,7 @@ pub const ENUM_VALUES_TEST_ENUM: [TestEnum; 3] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct TestEnum(pub i8); + #[allow(non_upper_case_globals)] impl TestEnum { pub const A: Self = Self(0); @@ -30,6 +34,7 @@ impl TestEnum { Self::B, Self::C, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -40,6 +45,7 @@ impl TestEnum { } } } + impl ::core::fmt::Debug for TestEnum { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -49,8 +55,10 @@ impl ::core::fmt::Debug for TestEnum { } } } + impl<'a> ::flatbuffers::Follow<'a> for TestEnum { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -60,6 +68,7 @@ impl<'a> ::flatbuffers::Follow<'a> for TestEnum { impl ::flatbuffers::Push for TestEnum { type Output = TestEnum; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -68,10 +77,12 @@ impl ::flatbuffers::Push for TestEnum { impl ::flatbuffers::EndianScalar for TestEnum { type Scalar = i8; + #[inline] fn to_little_endian(self) -> i8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i8) -> Self { 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..4e03e2decd3 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 @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_FROM_INCLUDE: i64 = 0; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ @@ -15,6 +18,7 @@ pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct FromInclude(pub i64); + #[allow(non_upper_case_globals)] impl FromInclude { pub const IncludeVal: Self = Self(0); @@ -24,6 +28,7 @@ impl FromInclude { pub const ENUM_VALUES: &'static [Self] = &[ Self::IncludeVal, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -32,6 +37,7 @@ impl FromInclude { } } } + impl ::core::fmt::Debug for FromInclude { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -41,8 +47,10 @@ impl ::core::fmt::Debug for FromInclude { } } } + impl<'a> ::flatbuffers::Follow<'a> for FromInclude { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -52,6 +60,7 @@ impl<'a> ::flatbuffers::Follow<'a> for FromInclude { impl ::flatbuffers::Push for FromInclude { type Output = FromInclude; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -60,10 +69,12 @@ impl ::flatbuffers::Push for FromInclude { impl ::flatbuffers::EndianScalar for FromInclude { type Scalar = i64; + #[inline] fn to_little_endian(self) -> i64 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i64) -> Self { 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..5e969c2dcd3 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TableBOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableB<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableB<'a> { type Inner = TableB<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> TableB<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableB { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -67,9 +70,11 @@ impl ::flatbuffers::Verifiable for TableB<'_> { Ok(()) } } + pub struct TableBArgs<'a> { pub a: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableBArgs<'a> { #[inline] fn default() -> Self { @@ -83,11 +88,13 @@ pub struct TableBBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { #[inline] pub fn add_a(&mut self, a: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableB::VT_A, a); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableBBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -96,6 +103,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -110,11 +118,13 @@ impl ::core::fmt::Debug for TableB<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableBT { pub a: Option>, } + impl Default for TableBT { fn default() -> Self { Self { @@ -122,6 +132,7 @@ impl Default for TableBT { } } } + impl TableBT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &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..e8639acf2b6 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 @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct Unused, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Unused(pub [u8; 4]); + impl Default for Unused { fn default() -> Self { Self([0; 4]) } } + impl ::core::fmt::Debug for Unused { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Unused") @@ -20,27 +23,34 @@ impl ::core::fmt::Debug for Unused { } impl ::flatbuffers::SimpleToVerifyInSlice for Unused {} + impl<'a> ::flatbuffers::Follow<'a> for Unused { type Inner = &'a Unused; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Unused>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Unused { type Inner = &'a Unused; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Unused { type Output = Unused; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -110,6 +120,7 @@ impl<'a> Unused { pub struct UnusedT { pub a: i32, } + impl UnusedT { pub fn pack(&self) -> Unused { Unused::new( @@ -117,4 +128,3 @@ impl UnusedT { ) } } - diff --git a/tests/include_test1/table_a_generated.rs b/tests/include_test1/table_a_generated.rs index ca29250dc3a..2558b840659 100644 --- a/tests/include_test1/table_a_generated.rs +++ b/tests/include_test1/table_a_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TableAOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableA<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableA<'a> { type Inner = TableA<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> TableA<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableA { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -67,9 +70,11 @@ impl ::flatbuffers::Verifiable for TableA<'_> { Ok(()) } } + pub struct TableAArgs<'a> { pub b: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableAArgs<'a> { #[inline] fn default() -> Self { @@ -83,11 +88,13 @@ pub struct TableABuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { #[inline] pub fn add_b(&mut self, b: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableA::VT_B, b); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableABuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -96,6 +103,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -110,11 +118,13 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableAT { pub b: Option>, } + impl Default for TableAT { fn default() -> Self { Self { @@ -122,6 +132,7 @@ impl Default for TableAT { } } } + impl TableAT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, diff --git a/tests/include_test1_generated.rs b/tests/include_test1_generated.rs index c4575b88db2..bb00aa8fc65 100644 --- a/tests/include_test1_generated.rs +++ b/tests/include_test1_generated.rs @@ -1,17 +1,17 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated - extern crate alloc; pub enum TableAOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableA<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableA<'a> { type Inner = TableA<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -29,6 +29,7 @@ impl<'a> TableA<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableA { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -68,9 +69,11 @@ impl ::flatbuffers::Verifiable for TableA<'_> { Ok(()) } } + pub struct TableAArgs<'a> { pub b: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableAArgs<'a> { #[inline] fn default() -> Self { @@ -84,11 +87,13 @@ pub struct TableABuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { #[inline] pub fn add_b(&mut self, b: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableA::VT_B, b); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableABuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -97,6 +102,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -111,11 +117,13 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableAT { pub b: Option>, } + impl Default for TableAT { fn default() -> Self { Self { @@ -123,6 +131,7 @@ impl Default for TableAT { } } } + impl TableAT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, @@ -136,344 +145,374 @@ impl TableAT { }) } } + #[allow(unused_imports, dead_code)] pub mod my_game { + extern crate alloc; + + #[allow(unused_imports, dead_code)] + pub mod other_name_space { + extern crate alloc; + + #[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; + + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + pub const ENUM_MAX_FROM_INCLUDE: i64 = 0; + + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ + FromInclude::IncludeVal, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct FromInclude(pub i64); + + #[allow(non_upper_case_globals)] + impl FromInclude { + pub const IncludeVal: Self = Self(0); + + pub const ENUM_MIN: i64 = 0; + pub const ENUM_MAX: i64 = 0; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::IncludeVal, + ]; + + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::IncludeVal => Some("IncludeVal"), + _ => None, + } + } + } -extern crate alloc; -#[allow(unused_imports, dead_code)] -pub mod other_name_space { + impl ::core::fmt::Debug for FromInclude { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } -extern crate alloc; + impl<'a> ::flatbuffers::Follow<'a> for FromInclude { + type Inner = Self; -#[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; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_FROM_INCLUDE: i64 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ - FromInclude::IncludeVal, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct FromInclude(pub i64); -#[allow(non_upper_case_globals)] -impl FromInclude { - pub const IncludeVal: Self = Self(0); - - pub const ENUM_MIN: i64 = 0; - pub const ENUM_MAX: i64 = 0; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::IncludeVal, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::IncludeVal => Some("IncludeVal"), - _ => None, + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; + Self(b) + } } - } -} -impl ::core::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) + + impl ::flatbuffers::Push for FromInclude { + type Output = FromInclude; + + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; + } } - } -} -impl<'a> ::flatbuffers::Follow<'a> for FromInclude { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; - Self(b) - } -} -impl ::flatbuffers::Push for FromInclude { - type Output = FromInclude; - #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; + impl ::flatbuffers::EndianScalar for FromInclude { + type Scalar = i64; + + #[inline] + fn to_little_endian(self) -> i64 { + self.0.to_le() + } + + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i64) -> Self { + let b = i64::from_le(v); + Self(b) + } } -} -impl ::flatbuffers::EndianScalar for FromInclude { - type Scalar = i64; - #[inline] - fn to_little_endian(self) -> i64 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i64) -> Self { - let b = i64::from_le(v); - Self(b) - } -} + impl<'a> ::flatbuffers::Verifiable for FromInclude { + #[inline] + fn run_verifier( + v: &mut ::flatbuffers::Verifier, pos: usize + ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { + i64::run_verifier(v, pos) + } + } -impl<'a> ::flatbuffers::Verifiable for FromInclude { - #[inline] - fn run_verifier( - v: &mut ::flatbuffers::Verifier, pos: usize - ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { - i64::run_verifier(v, pos) - } -} + impl ::flatbuffers::SimpleToVerifyInSlice for FromInclude {} -impl ::flatbuffers::SimpleToVerifyInSlice for FromInclude {} -// struct Unused, aligned to 4 -#[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] -pub struct Unused(pub [u8; 4]); -impl Default for Unused { - fn default() -> Self { - Self([0; 4]) - } -} -impl ::core::fmt::Debug for Unused { - fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - f.debug_struct("Unused") - .field("a", &self.a()) - .finish() - } -} + // struct Unused, aligned to 4 + #[repr(transparent)] + #[derive(Clone, Copy, PartialEq)] + pub struct Unused(pub [u8; 4]); -impl ::flatbuffers::SimpleToVerifyInSlice for Unused {} -impl<'a> ::flatbuffers::Follow<'a> for Unused { - type Inner = &'a Unused; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - unsafe { <&'a Unused>::follow(buf, loc) } - } -} -impl<'a> ::flatbuffers::Follow<'a> for &'a Unused { - type Inner = &'a Unused; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } - } -} -impl<'b> ::flatbuffers::Push for Unused { - type Output = Unused; - #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, ::size()) }; - dst.copy_from_slice(src); + impl Default for Unused { + fn default() -> Self { + Self([0; 4]) + } } - #[inline] - fn alignment() -> ::flatbuffers::PushAlignment { - ::flatbuffers::PushAlignment::new(4) + + impl ::core::fmt::Debug for Unused { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + f.debug_struct("Unused") + .field("a", &self.a()) + .finish() + } } -} -impl<'a> ::flatbuffers::Verifiable for Unused { - #[inline] - fn run_verifier( - v: &mut ::flatbuffers::Verifier, pos: usize - ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { - v.in_buffer::(pos) - } -} + impl ::flatbuffers::SimpleToVerifyInSlice for Unused {} -impl<'a> Unused { - #[allow(clippy::too_many_arguments)] - pub fn new( - a: i32, - ) -> Self { - let mut s = Self([0; 4]); - s.set_a(a); - s - } + impl<'a> ::flatbuffers::Follow<'a> for Unused { + type Inner = &'a Unused; - pub const fn get_fully_qualified_name() -> &'static str { - "MyGame.OtherNameSpace.Unused" - } + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe { <&'a Unused>::follow(buf, loc) } + } + } - pub fn a(&self) -> i32 { - let mut mem = ::core::mem::MaybeUninit::<::Scalar>::uninit(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid value in this slot - ::flatbuffers::EndianScalar::from_little_endian(unsafe { - ::core::ptr::copy_nonoverlapping( - self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - ::core::mem::size_of::<::Scalar>(), - ); - mem.assume_init() - }) - } + impl<'a> ::flatbuffers::Follow<'a> for &'a Unused { + type Inner = &'a Unused; - pub fn set_a(&mut self, x: i32) { - let x_le = ::flatbuffers::EndianScalar::to_little_endian(x); - // Safety: - // Created from a valid Table for this object - // Which contains a valid value in this slot - unsafe { - ::core::ptr::copy_nonoverlapping( - &x_le as *const _ as *const u8, - self.0[0..].as_mut_ptr(), - ::core::mem::size_of::<::Scalar>(), - ); + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } + } } - } - pub fn unpack(&self) -> UnusedT { - UnusedT { - a: self.a(), + impl<'b> ::flatbuffers::Push for Unused { + type Output = Unused; + + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, ::size()) }; + dst.copy_from_slice(src); + } + + #[inline] + fn alignment() -> ::flatbuffers::PushAlignment { + ::flatbuffers::PushAlignment::new(4) + } } - } -} -#[derive(Debug, Clone, PartialEq, Default)] -pub struct UnusedT { - pub a: i32, -} -impl UnusedT { - pub fn pack(&self) -> Unused { - Unused::new( - self.a, - ) - } -} + impl<'a> ::flatbuffers::Verifiable for Unused { + #[inline] + fn run_verifier( + v: &mut ::flatbuffers::Verifier, pos: usize + ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { + v.in_buffer::(pos) + } + } -pub enum TableBOffset {} -#[derive(Copy, Clone, PartialEq)] + impl<'a> Unused { + #[allow(clippy::too_many_arguments)] + pub fn new( + a: i32, + ) -> Self { + let mut s = Self([0; 4]); + s.set_a(a); + s + } + + pub const fn get_fully_qualified_name() -> &'static str { + "MyGame.OtherNameSpace.Unused" + } + + pub fn a(&self) -> i32 { + let mut mem = ::core::mem::MaybeUninit::<::Scalar>::uninit(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + ::flatbuffers::EndianScalar::from_little_endian(unsafe { + ::core::ptr::copy_nonoverlapping( + self.0[0..].as_ptr(), + mem.as_mut_ptr() as *mut u8, + ::core::mem::size_of::<::Scalar>(), + ); + mem.assume_init() + }) + } + + pub fn set_a(&mut self, x: i32) { + let x_le = ::flatbuffers::EndianScalar::to_little_endian(x); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + unsafe { + ::core::ptr::copy_nonoverlapping( + &x_le as *const _ as *const u8, + self.0[0..].as_mut_ptr(), + ::core::mem::size_of::<::Scalar>(), + ); + } + } + + pub fn unpack(&self) -> UnusedT { + UnusedT { + a: self.a(), + } + } + } -pub struct TableB<'a> { - pub _tab: ::flatbuffers::Table<'a>, -} + #[derive(Debug, Clone, PartialEq, Default)] + pub struct UnusedT { + pub a: i32, + } -impl<'a> ::flatbuffers::Follow<'a> for TableB<'a> { - type Inner = TableB<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } - } -} + impl UnusedT { + pub fn pack(&self) -> Unused { + Unused::new( + self.a, + ) + } + } -impl<'a> TableB<'a> { - pub const VT_A: ::flatbuffers::VOffsetT = 4; + pub enum TableBOffset {} - pub const fn get_fully_qualified_name() -> &'static str { - "MyGame.OtherNameSpace.TableB" - } + #[derive(Copy, Clone, PartialEq)] + pub struct TableB<'a> { + pub _tab: ::flatbuffers::Table<'a>, + } - #[inline] - pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { - TableB { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args TableBArgs<'args> - ) -> ::flatbuffers::WIPOffset> { - let mut builder = TableBBuilder::new(_fbb); - if let Some(x) = args.a { builder.add_a(x); } - builder.finish() - } + impl<'a> ::flatbuffers::Follow<'a> for TableB<'a> { + type Inner = TableB<'a>; - pub fn unpack(&self) -> TableBT { - let a = self.a().map(|x| { - alloc::boxed::Box::new(x.unpack()) - }); - TableBT { - a, + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } + } } - } - #[inline] - pub fn a(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(TableB::VT_A, None)} - } -} + impl<'a> TableB<'a> { + pub const VT_A: ::flatbuffers::VOffsetT = 4; + + pub const fn get_fully_qualified_name() -> &'static str { + "MyGame.OtherNameSpace.TableB" + } + + #[inline] + pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { + TableB { _tab: table } + } + + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args TableBArgs<'args> + ) -> ::flatbuffers::WIPOffset> { + let mut builder = TableBBuilder::new(_fbb); + if let Some(x) = args.a { builder.add_a(x); } + builder.finish() + } + + pub fn unpack(&self) -> TableBT { + let a = self.a().map(|x| { + alloc::boxed::Box::new(x.unpack()) + }); + TableBT { + a, + } + } + + #[inline] + pub fn a(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(TableB::VT_A, None)} + } + } -impl ::flatbuffers::Verifiable for TableB<'_> { - #[inline] - fn run_verifier( - v: &mut ::flatbuffers::Verifier, pos: usize - ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { - v.visit_table(pos)? + impl ::flatbuffers::Verifiable for TableB<'_> { + #[inline] + fn run_verifier( + v: &mut ::flatbuffers::Verifier, pos: usize + ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? .visit_field::<::flatbuffers::ForwardsUOffset>("a", Self::VT_A, false)? .finish(); - Ok(()) - } -} -pub struct TableBArgs<'a> { - pub a: Option<::flatbuffers::WIPOffset>>, -} -impl<'a> Default for TableBArgs<'a> { - #[inline] - fn default() -> Self { - TableBArgs { - a: None, + Ok(()) + } } - } -} -pub struct TableBBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { - fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, - start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, -} -impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { - #[inline] - pub fn add_a(&mut self, a: ::flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableB::VT_A, a); - } - #[inline] - pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableBBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - TableBBuilder { - fbb_: _fbb, - start_: start, + pub struct TableBArgs<'a> { + pub a: Option<::flatbuffers::WIPOffset>>, } - } - #[inline] - pub fn finish(self) -> ::flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - ::flatbuffers::WIPOffset::new(o.value()) - } -} -impl ::core::fmt::Debug for TableB<'_> { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - let mut ds = f.debug_struct("TableB"); - ds.field("a", &self.a()); - ds.finish() - } -} -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] -pub struct TableBT { - pub a: Option>, -} -impl Default for TableBT { - fn default() -> Self { - Self { - a: None, + impl<'a> Default for TableBArgs<'a> { + #[inline] + fn default() -> Self { + TableBArgs { + a: None, + } + } } - } -} -impl TableBT { - pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( - &self, - _fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A> - ) -> ::flatbuffers::WIPOffset> { - let a = self.a.as_ref().map(|x|{ - x.pack(_fbb) - }); - TableB::create(_fbb, &TableBArgs{ - a, - }) - } -} -} // pub mod OtherNameSpace -} // pub mod MyGame + pub struct TableBBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { + fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, + start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, + } + + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { + #[inline] + pub fn add_a(&mut self, a: ::flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableB::VT_A, a); + } + + #[inline] + pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableBBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + TableBBuilder { + fbb_: _fbb, + start_: start, + } + } + + #[inline] + pub fn finish(self) -> ::flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + ::flatbuffers::WIPOffset::new(o.value()) + } + } + + impl ::core::fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + let mut ds = f.debug_struct("TableB"); + ds.field("a", &self.a()); + ds.finish() + } + } + + #[non_exhaustive] + #[derive(Debug, Clone, PartialEq)] + pub struct TableBT { + pub a: Option>, + } + + impl Default for TableBT { + fn default() -> Self { + Self { + a: None, + } + } + } + + impl TableBT { + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( + &self, + _fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A> + ) -> ::flatbuffers::WIPOffset> { + let a = self.a.as_ref().map(|x|{ + x.pack(_fbb) + }); + TableB::create(_fbb, &TableBArgs{ + a, + }) + } + } + } // pub mod OtherNameSpace +} // pub mod MyGame 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..4e03e2decd3 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 @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_FROM_INCLUDE: i64 = 0; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ @@ -15,6 +18,7 @@ pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct FromInclude(pub i64); + #[allow(non_upper_case_globals)] impl FromInclude { pub const IncludeVal: Self = Self(0); @@ -24,6 +28,7 @@ impl FromInclude { pub const ENUM_VALUES: &'static [Self] = &[ Self::IncludeVal, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -32,6 +37,7 @@ impl FromInclude { } } } + impl ::core::fmt::Debug for FromInclude { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -41,8 +47,10 @@ impl ::core::fmt::Debug for FromInclude { } } } + impl<'a> ::flatbuffers::Follow<'a> for FromInclude { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -52,6 +60,7 @@ impl<'a> ::flatbuffers::Follow<'a> for FromInclude { impl ::flatbuffers::Push for FromInclude { type Output = FromInclude; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -60,10 +69,12 @@ impl ::flatbuffers::Push for FromInclude { impl ::flatbuffers::EndianScalar for FromInclude { type Scalar = i64; + #[inline] fn to_little_endian(self) -> i64 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i64) -> Self { 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..5e969c2dcd3 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TableBOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableB<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableB<'a> { type Inner = TableB<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> TableB<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableB { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -67,9 +70,11 @@ impl ::flatbuffers::Verifiable for TableB<'_> { Ok(()) } } + pub struct TableBArgs<'a> { pub a: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableBArgs<'a> { #[inline] fn default() -> Self { @@ -83,11 +88,13 @@ pub struct TableBBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { #[inline] pub fn add_a(&mut self, a: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableB::VT_A, a); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableBBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -96,6 +103,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -110,11 +118,13 @@ impl ::core::fmt::Debug for TableB<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableBT { pub a: Option>, } + impl Default for TableBT { fn default() -> Self { Self { @@ -122,6 +132,7 @@ impl Default for TableBT { } } } + impl TableBT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &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..e8639acf2b6 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 @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct Unused, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Unused(pub [u8; 4]); + impl Default for Unused { fn default() -> Self { Self([0; 4]) } } + impl ::core::fmt::Debug for Unused { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Unused") @@ -20,27 +23,34 @@ impl ::core::fmt::Debug for Unused { } impl ::flatbuffers::SimpleToVerifyInSlice for Unused {} + impl<'a> ::flatbuffers::Follow<'a> for Unused { type Inner = &'a Unused; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Unused>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Unused { type Inner = &'a Unused; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Unused { type Output = Unused; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -110,6 +120,7 @@ impl<'a> Unused { pub struct UnusedT { pub a: i32, } + impl UnusedT { pub fn pack(&self) -> Unused { Unused::new( @@ -117,4 +128,3 @@ impl UnusedT { ) } } - diff --git a/tests/include_test2/table_a_generated.rs b/tests/include_test2/table_a_generated.rs index ca29250dc3a..2558b840659 100644 --- a/tests/include_test2/table_a_generated.rs +++ b/tests/include_test2/table_a_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TableAOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableA<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableA<'a> { type Inner = TableA<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> TableA<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableA { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -67,9 +70,11 @@ impl ::flatbuffers::Verifiable for TableA<'_> { Ok(()) } } + pub struct TableAArgs<'a> { pub b: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableAArgs<'a> { #[inline] fn default() -> Self { @@ -83,11 +88,13 @@ pub struct TableABuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { #[inline] pub fn add_b(&mut self, b: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableA::VT_B, b); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableABuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -96,6 +103,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -110,11 +118,13 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableAT { pub b: Option>, } + impl Default for TableAT { fn default() -> Self { Self { @@ -122,6 +132,7 @@ impl Default for TableAT { } } } + impl TableAT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, diff --git a/tests/include_test2_generated.rs b/tests/include_test2_generated.rs index c4575b88db2..bb00aa8fc65 100644 --- a/tests/include_test2_generated.rs +++ b/tests/include_test2_generated.rs @@ -1,17 +1,17 @@ // automatically generated by the FlatBuffers compiler, do not modify // @generated - extern crate alloc; pub enum TableAOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableA<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableA<'a> { type Inner = TableA<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -29,6 +29,7 @@ impl<'a> TableA<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableA { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -68,9 +69,11 @@ impl ::flatbuffers::Verifiable for TableA<'_> { Ok(()) } } + pub struct TableAArgs<'a> { pub b: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableAArgs<'a> { #[inline] fn default() -> Self { @@ -84,11 +87,13 @@ pub struct TableABuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { #[inline] pub fn add_b(&mut self, b: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableA::VT_B, b); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableABuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -97,6 +102,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -111,11 +117,13 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableAT { pub b: Option>, } + impl Default for TableAT { fn default() -> Self { Self { @@ -123,6 +131,7 @@ impl Default for TableAT { } } } + impl TableAT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, @@ -136,344 +145,374 @@ impl TableAT { }) } } + #[allow(unused_imports, dead_code)] pub mod my_game { + extern crate alloc; + + #[allow(unused_imports, dead_code)] + pub mod other_name_space { + extern crate alloc; + + #[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; + + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + pub const ENUM_MAX_FROM_INCLUDE: i64 = 0; + + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ + FromInclude::IncludeVal, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct FromInclude(pub i64); + + #[allow(non_upper_case_globals)] + impl FromInclude { + pub const IncludeVal: Self = Self(0); + + pub const ENUM_MIN: i64 = 0; + pub const ENUM_MAX: i64 = 0; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::IncludeVal, + ]; + + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::IncludeVal => Some("IncludeVal"), + _ => None, + } + } + } -extern crate alloc; -#[allow(unused_imports, dead_code)] -pub mod other_name_space { + impl ::core::fmt::Debug for FromInclude { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } -extern crate alloc; + impl<'a> ::flatbuffers::Follow<'a> for FromInclude { + type Inner = Self; -#[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; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_FROM_INCLUDE: i64 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ - FromInclude::IncludeVal, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct FromInclude(pub i64); -#[allow(non_upper_case_globals)] -impl FromInclude { - pub const IncludeVal: Self = Self(0); - - pub const ENUM_MIN: i64 = 0; - pub const ENUM_MAX: i64 = 0; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::IncludeVal, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::IncludeVal => Some("IncludeVal"), - _ => None, + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; + Self(b) + } } - } -} -impl ::core::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) + + impl ::flatbuffers::Push for FromInclude { + type Output = FromInclude; + + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; + } } - } -} -impl<'a> ::flatbuffers::Follow<'a> for FromInclude { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; - Self(b) - } -} -impl ::flatbuffers::Push for FromInclude { - type Output = FromInclude; - #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; + impl ::flatbuffers::EndianScalar for FromInclude { + type Scalar = i64; + + #[inline] + fn to_little_endian(self) -> i64 { + self.0.to_le() + } + + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i64) -> Self { + let b = i64::from_le(v); + Self(b) + } } -} -impl ::flatbuffers::EndianScalar for FromInclude { - type Scalar = i64; - #[inline] - fn to_little_endian(self) -> i64 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i64) -> Self { - let b = i64::from_le(v); - Self(b) - } -} + impl<'a> ::flatbuffers::Verifiable for FromInclude { + #[inline] + fn run_verifier( + v: &mut ::flatbuffers::Verifier, pos: usize + ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { + i64::run_verifier(v, pos) + } + } -impl<'a> ::flatbuffers::Verifiable for FromInclude { - #[inline] - fn run_verifier( - v: &mut ::flatbuffers::Verifier, pos: usize - ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { - i64::run_verifier(v, pos) - } -} + impl ::flatbuffers::SimpleToVerifyInSlice for FromInclude {} -impl ::flatbuffers::SimpleToVerifyInSlice for FromInclude {} -// struct Unused, aligned to 4 -#[repr(transparent)] -#[derive(Clone, Copy, PartialEq)] -pub struct Unused(pub [u8; 4]); -impl Default for Unused { - fn default() -> Self { - Self([0; 4]) - } -} -impl ::core::fmt::Debug for Unused { - fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - f.debug_struct("Unused") - .field("a", &self.a()) - .finish() - } -} + // struct Unused, aligned to 4 + #[repr(transparent)] + #[derive(Clone, Copy, PartialEq)] + pub struct Unused(pub [u8; 4]); -impl ::flatbuffers::SimpleToVerifyInSlice for Unused {} -impl<'a> ::flatbuffers::Follow<'a> for Unused { - type Inner = &'a Unused; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - unsafe { <&'a Unused>::follow(buf, loc) } - } -} -impl<'a> ::flatbuffers::Follow<'a> for &'a Unused { - type Inner = &'a Unused; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } - } -} -impl<'b> ::flatbuffers::Push for Unused { - type Output = Unused; - #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, ::size()) }; - dst.copy_from_slice(src); + impl Default for Unused { + fn default() -> Self { + Self([0; 4]) + } } - #[inline] - fn alignment() -> ::flatbuffers::PushAlignment { - ::flatbuffers::PushAlignment::new(4) + + impl ::core::fmt::Debug for Unused { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + f.debug_struct("Unused") + .field("a", &self.a()) + .finish() + } } -} -impl<'a> ::flatbuffers::Verifiable for Unused { - #[inline] - fn run_verifier( - v: &mut ::flatbuffers::Verifier, pos: usize - ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { - v.in_buffer::(pos) - } -} + impl ::flatbuffers::SimpleToVerifyInSlice for Unused {} -impl<'a> Unused { - #[allow(clippy::too_many_arguments)] - pub fn new( - a: i32, - ) -> Self { - let mut s = Self([0; 4]); - s.set_a(a); - s - } + impl<'a> ::flatbuffers::Follow<'a> for Unused { + type Inner = &'a Unused; - pub const fn get_fully_qualified_name() -> &'static str { - "MyGame.OtherNameSpace.Unused" - } + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe { <&'a Unused>::follow(buf, loc) } + } + } - pub fn a(&self) -> i32 { - let mut mem = ::core::mem::MaybeUninit::<::Scalar>::uninit(); - // Safety: - // Created from a valid Table for this object - // Which contains a valid value in this slot - ::flatbuffers::EndianScalar::from_little_endian(unsafe { - ::core::ptr::copy_nonoverlapping( - self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - ::core::mem::size_of::<::Scalar>(), - ); - mem.assume_init() - }) - } + impl<'a> ::flatbuffers::Follow<'a> for &'a Unused { + type Inner = &'a Unused; - pub fn set_a(&mut self, x: i32) { - let x_le = ::flatbuffers::EndianScalar::to_little_endian(x); - // Safety: - // Created from a valid Table for this object - // Which contains a valid value in this slot - unsafe { - ::core::ptr::copy_nonoverlapping( - &x_le as *const _ as *const u8, - self.0[0..].as_mut_ptr(), - ::core::mem::size_of::<::Scalar>(), - ); + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } + } } - } - pub fn unpack(&self) -> UnusedT { - UnusedT { - a: self.a(), + impl<'b> ::flatbuffers::Push for Unused { + type Output = Unused; + + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, ::size()) }; + dst.copy_from_slice(src); + } + + #[inline] + fn alignment() -> ::flatbuffers::PushAlignment { + ::flatbuffers::PushAlignment::new(4) + } } - } -} -#[derive(Debug, Clone, PartialEq, Default)] -pub struct UnusedT { - pub a: i32, -} -impl UnusedT { - pub fn pack(&self) -> Unused { - Unused::new( - self.a, - ) - } -} + impl<'a> ::flatbuffers::Verifiable for Unused { + #[inline] + fn run_verifier( + v: &mut ::flatbuffers::Verifier, pos: usize + ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { + v.in_buffer::(pos) + } + } -pub enum TableBOffset {} -#[derive(Copy, Clone, PartialEq)] + impl<'a> Unused { + #[allow(clippy::too_many_arguments)] + pub fn new( + a: i32, + ) -> Self { + let mut s = Self([0; 4]); + s.set_a(a); + s + } + + pub const fn get_fully_qualified_name() -> &'static str { + "MyGame.OtherNameSpace.Unused" + } + + pub fn a(&self) -> i32 { + let mut mem = ::core::mem::MaybeUninit::<::Scalar>::uninit(); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + ::flatbuffers::EndianScalar::from_little_endian(unsafe { + ::core::ptr::copy_nonoverlapping( + self.0[0..].as_ptr(), + mem.as_mut_ptr() as *mut u8, + ::core::mem::size_of::<::Scalar>(), + ); + mem.assume_init() + }) + } + + pub fn set_a(&mut self, x: i32) { + let x_le = ::flatbuffers::EndianScalar::to_little_endian(x); + // Safety: + // Created from a valid Table for this object + // Which contains a valid value in this slot + unsafe { + ::core::ptr::copy_nonoverlapping( + &x_le as *const _ as *const u8, + self.0[0..].as_mut_ptr(), + ::core::mem::size_of::<::Scalar>(), + ); + } + } + + pub fn unpack(&self) -> UnusedT { + UnusedT { + a: self.a(), + } + } + } -pub struct TableB<'a> { - pub _tab: ::flatbuffers::Table<'a>, -} + #[derive(Debug, Clone, PartialEq, Default)] + pub struct UnusedT { + pub a: i32, + } -impl<'a> ::flatbuffers::Follow<'a> for TableB<'a> { - type Inner = TableB<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } - } -} + impl UnusedT { + pub fn pack(&self) -> Unused { + Unused::new( + self.a, + ) + } + } -impl<'a> TableB<'a> { - pub const VT_A: ::flatbuffers::VOffsetT = 4; + pub enum TableBOffset {} - pub const fn get_fully_qualified_name() -> &'static str { - "MyGame.OtherNameSpace.TableB" - } + #[derive(Copy, Clone, PartialEq)] + pub struct TableB<'a> { + pub _tab: ::flatbuffers::Table<'a>, + } - #[inline] - pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { - TableB { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args TableBArgs<'args> - ) -> ::flatbuffers::WIPOffset> { - let mut builder = TableBBuilder::new(_fbb); - if let Some(x) = args.a { builder.add_a(x); } - builder.finish() - } + impl<'a> ::flatbuffers::Follow<'a> for TableB<'a> { + type Inner = TableB<'a>; - pub fn unpack(&self) -> TableBT { - let a = self.a().map(|x| { - alloc::boxed::Box::new(x.unpack()) - }); - TableBT { - a, + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } + } } - } - #[inline] - pub fn a(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(TableB::VT_A, None)} - } -} + impl<'a> TableB<'a> { + pub const VT_A: ::flatbuffers::VOffsetT = 4; + + pub const fn get_fully_qualified_name() -> &'static str { + "MyGame.OtherNameSpace.TableB" + } + + #[inline] + pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { + TableB { _tab: table } + } + + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args TableBArgs<'args> + ) -> ::flatbuffers::WIPOffset> { + let mut builder = TableBBuilder::new(_fbb); + if let Some(x) = args.a { builder.add_a(x); } + builder.finish() + } + + pub fn unpack(&self) -> TableBT { + let a = self.a().map(|x| { + alloc::boxed::Box::new(x.unpack()) + }); + TableBT { + a, + } + } + + #[inline] + pub fn a(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(TableB::VT_A, None)} + } + } -impl ::flatbuffers::Verifiable for TableB<'_> { - #[inline] - fn run_verifier( - v: &mut ::flatbuffers::Verifier, pos: usize - ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { - v.visit_table(pos)? + impl ::flatbuffers::Verifiable for TableB<'_> { + #[inline] + fn run_verifier( + v: &mut ::flatbuffers::Verifier, pos: usize + ) -> Result<(), ::flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? .visit_field::<::flatbuffers::ForwardsUOffset>("a", Self::VT_A, false)? .finish(); - Ok(()) - } -} -pub struct TableBArgs<'a> { - pub a: Option<::flatbuffers::WIPOffset>>, -} -impl<'a> Default for TableBArgs<'a> { - #[inline] - fn default() -> Self { - TableBArgs { - a: None, + Ok(()) + } } - } -} -pub struct TableBBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { - fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, - start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, -} -impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { - #[inline] - pub fn add_a(&mut self, a: ::flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableB::VT_A, a); - } - #[inline] - pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableBBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - TableBBuilder { - fbb_: _fbb, - start_: start, + pub struct TableBArgs<'a> { + pub a: Option<::flatbuffers::WIPOffset>>, } - } - #[inline] - pub fn finish(self) -> ::flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - ::flatbuffers::WIPOffset::new(o.value()) - } -} -impl ::core::fmt::Debug for TableB<'_> { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - let mut ds = f.debug_struct("TableB"); - ds.field("a", &self.a()); - ds.finish() - } -} -#[non_exhaustive] -#[derive(Debug, Clone, PartialEq)] -pub struct TableBT { - pub a: Option>, -} -impl Default for TableBT { - fn default() -> Self { - Self { - a: None, + impl<'a> Default for TableBArgs<'a> { + #[inline] + fn default() -> Self { + TableBArgs { + a: None, + } + } } - } -} -impl TableBT { - pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( - &self, - _fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A> - ) -> ::flatbuffers::WIPOffset> { - let a = self.a.as_ref().map(|x|{ - x.pack(_fbb) - }); - TableB::create(_fbb, &TableBArgs{ - a, - }) - } -} -} // pub mod OtherNameSpace -} // pub mod MyGame + pub struct TableBBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { + fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, + start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, + } + + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { + #[inline] + pub fn add_a(&mut self, a: ::flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableB::VT_A, a); + } + + #[inline] + pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableBBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + TableBBuilder { + fbb_: _fbb, + start_: start, + } + } + + #[inline] + pub fn finish(self) -> ::flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + ::flatbuffers::WIPOffset::new(o.value()) + } + } + + impl ::core::fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + let mut ds = f.debug_struct("TableB"); + ds.field("a", &self.a()); + ds.finish() + } + } + + #[non_exhaustive] + #[derive(Debug, Clone, PartialEq)] + pub struct TableBT { + pub a: Option>, + } + + impl Default for TableBT { + fn default() -> Self { + Self { + a: None, + } + } + } + + impl TableBT { + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( + &self, + _fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A> + ) -> ::flatbuffers::WIPOffset> { + let a = self.a.as_ref().map(|x|{ + x.pack(_fbb) + }); + TableB::create(_fbb, &TableBArgs{ + a, + }) + } + } + } // pub mod OtherNameSpace +} // pub mod MyGame diff --git a/tests/keyword_test/keyword_test/abc_generated.rs b/tests/keyword_test/keyword_test/abc_generated.rs index 43df27b6dde..a8da0581e85 100644 --- a/tests/keyword_test/keyword_test/abc_generated.rs +++ b/tests/keyword_test/keyword_test/abc_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ABC: i32 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ABC: [ABC; 3] = [ @@ -17,6 +20,7 @@ pub const ENUM_VALUES_ABC: [ABC; 3] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct ABC(pub i32); + #[allow(non_upper_case_globals)] impl ABC { pub const void: Self = Self(0); @@ -30,6 +34,7 @@ impl ABC { Self::where_, Self::stackalloc, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -40,6 +45,7 @@ impl ABC { } } } + impl ::core::fmt::Debug for ABC { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -49,8 +55,10 @@ impl ::core::fmt::Debug for ABC { } } } + impl<'a> ::flatbuffers::Follow<'a> for ABC { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -60,6 +68,7 @@ impl<'a> ::flatbuffers::Follow<'a> for ABC { impl ::flatbuffers::Push for ABC { type Output = ABC; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -68,10 +77,12 @@ impl ::flatbuffers::Push for ABC { impl ::flatbuffers::EndianScalar for ABC { type Scalar = i32; + #[inline] fn to_little_endian(self) -> i32 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i32) -> Self { 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..f8c0505761c 100644 --- a/tests/keyword_test/keyword_test/keywords_in_table_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum KeywordsInTableOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct KeywordsInTable<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for KeywordsInTable<'a> { type Inner = KeywordsInTable<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -31,6 +33,7 @@ impl<'a> KeywordsInTable<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { KeywordsInTable { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -64,6 +67,7 @@ impl<'a> KeywordsInTable<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(KeywordsInTable::VT_IS, Some(ABC::void)).unwrap()} } + #[inline] pub fn private(&self) -> public { // Safety: @@ -71,6 +75,7 @@ impl<'a> KeywordsInTable<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(KeywordsInTable::VT_PRIVATE, Some(public::NONE)).unwrap()} } + #[inline] pub fn type_(&self) -> i32 { // Safety: @@ -78,6 +83,7 @@ impl<'a> KeywordsInTable<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(KeywordsInTable::VT_TYPE_, Some(0)).unwrap()} } + #[inline] pub fn default(&self) -> bool { // Safety: @@ -101,12 +107,14 @@ impl ::flatbuffers::Verifiable for KeywordsInTable<'_> { Ok(()) } } + pub struct KeywordsInTableArgs { pub is: ABC, pub private: public, pub type_: i32, pub default: bool, } + impl<'a> Default for KeywordsInTableArgs { #[inline] fn default() -> Self { @@ -123,23 +131,28 @@ pub struct KeywordsInTableBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> KeywordsInTableBuilder<'a, 'b, A> { #[inline] pub fn add_is(&mut self, is: ABC) { self.fbb_.push_slot::(KeywordsInTable::VT_IS, is, ABC::void); } + #[inline] pub fn add_private(&mut self, private: public) { self.fbb_.push_slot::(KeywordsInTable::VT_PRIVATE, private, public::NONE); } + #[inline] pub fn add_type_(&mut self, type_: i32) { self.fbb_.push_slot::(KeywordsInTable::VT_TYPE_, type_, 0); } + #[inline] pub fn add_default(&mut self, default: bool) { self.fbb_.push_slot::(KeywordsInTable::VT_DEFAULT, default, false); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> KeywordsInTableBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -148,6 +161,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> KeywordsInTableBuilder<'a, 'b start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -165,6 +179,7 @@ impl ::core::fmt::Debug for KeywordsInTable<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct KeywordsInTableT { @@ -173,6 +188,7 @@ pub struct KeywordsInTableT { pub type_: i32, pub default: bool, } + impl Default for KeywordsInTableT { fn default() -> Self { Self { @@ -183,6 +199,7 @@ impl Default for KeywordsInTableT { } } } + impl KeywordsInTableT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..fe31141724a 100644 --- a/tests/keyword_test/keyword_test/keywords_in_union_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_KEYWORDS_IN_UNION: u8 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_KEYWORDS_IN_UNION: [KeywordsInUnion; 3] = [ @@ -17,6 +20,7 @@ pub const ENUM_VALUES_KEYWORDS_IN_UNION: [KeywordsInUnion; 3] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct KeywordsInUnion(pub u8); + #[allow(non_upper_case_globals)] impl KeywordsInUnion { pub const NONE: Self = Self(0); @@ -30,6 +34,7 @@ impl KeywordsInUnion { Self::static_, Self::internal, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -40,6 +45,7 @@ impl KeywordsInUnion { } } } + impl ::core::fmt::Debug for KeywordsInUnion { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -49,8 +55,10 @@ impl ::core::fmt::Debug for KeywordsInUnion { } } } + impl<'a> ::flatbuffers::Follow<'a> for KeywordsInUnion { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -60,6 +68,7 @@ impl<'a> ::flatbuffers::Follow<'a> for KeywordsInUnion { impl ::flatbuffers::Push for KeywordsInUnion { type Output = KeywordsInUnion; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -68,10 +77,12 @@ impl ::flatbuffers::Push for KeywordsInUnion { impl ::flatbuffers::EndianScalar for KeywordsInUnion { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -90,6 +101,7 @@ impl<'a> ::flatbuffers::Verifiable for KeywordsInUnion { } impl ::flatbuffers::SimpleToVerifyInSlice for KeywordsInUnion {} + pub struct KeywordsInUnionUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -100,11 +112,13 @@ pub enum KeywordsInUnionT { Static_(alloc::boxed::Box), Internal(alloc::boxed::Box), } + impl Default for KeywordsInUnionT { fn default() -> Self { Self::NONE } } + impl KeywordsInUnionT { pub fn keywords_in_union_type(&self) -> KeywordsInUnion { match self { @@ -113,6 +127,7 @@ impl KeywordsInUnionT { Self::Internal(_) => KeywordsInUnion::internal, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, @@ -120,6 +135,7 @@ impl KeywordsInUnionT { Self::Internal(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE. pub fn take_static_(&mut self) -> Option> { if let Self::Static_(_) = self { @@ -133,14 +149,17 @@ impl KeywordsInUnionT { None } } + /// If the union variant matches, return a reference to the KeywordsInTableT. pub fn as_static_(&self) -> Option<&KeywordsInTableT> { if let Self::Static_(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the KeywordsInTableT. pub fn as_static__mut(&mut self) -> Option<&mut KeywordsInTableT> { 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> { if let Self::Internal(_) = self { @@ -154,12 +173,15 @@ impl KeywordsInUnionT { None } } + /// If the union variant matches, return a reference to the KeywordsInTableT. pub fn as_internal(&self) -> Option<&KeywordsInTableT> { if let Self::Internal(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the KeywordsInTableT. pub fn as_internal_mut(&mut self) -> Option<&mut KeywordsInTableT> { if let Self::Internal(v) = self { Some(v.as_mut()) } else { None } } } + diff --git a/tests/keyword_test/keyword_test/public_generated.rs b/tests/keyword_test/keyword_test/public_generated.rs index be9570cc499..a4a449e953e 100644 --- a/tests/keyword_test/keyword_test/public_generated.rs +++ b/tests/keyword_test/keyword_test/public_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_PUBLIC: i32 = 0; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_PUBLIC: [public; 1] = [ @@ -15,6 +18,7 @@ pub const ENUM_VALUES_PUBLIC: [public; 1] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct public(pub i32); + #[allow(non_upper_case_globals)] impl public { pub const NONE: Self = Self(0); @@ -24,6 +28,7 @@ impl public { pub const ENUM_VALUES: &'static [Self] = &[ Self::NONE, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -32,6 +37,7 @@ impl public { } } } + impl ::core::fmt::Debug for public { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -41,8 +47,10 @@ impl ::core::fmt::Debug for public { } } } + impl<'a> ::flatbuffers::Follow<'a> for public { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -52,6 +60,7 @@ impl<'a> ::flatbuffers::Follow<'a> for public { impl ::flatbuffers::Push for public { type Output = public; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -60,10 +69,12 @@ impl ::flatbuffers::Push for public { impl ::flatbuffers::EndianScalar for public { type Scalar = i32; + #[inline] fn to_little_endian(self) -> i32 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i32) -> Self { diff --git a/tests/keyword_test/keyword_test/table_2_generated.rs b/tests/keyword_test/keyword_test/table_2_generated.rs index a8e72bd4d08..4436a0f0711 100644 --- a/tests/keyword_test/keyword_test/table_2_generated.rs +++ b/tests/keyword_test/keyword_test/table_2_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum Table2Offset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct Table2<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Table2<'a> { type Inner = Table2<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -29,6 +31,7 @@ impl<'a> Table2<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Table2 { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -67,6 +70,7 @@ impl<'a> Table2<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Table2::VT_TYPE_TYPE, Some(KeywordsInUnion::NONE)).unwrap()} } + #[inline] pub fn type_(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -74,6 +78,7 @@ impl<'a> Table2<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(Table2::VT_TYPE_, None)} } + #[inline] #[allow(non_snake_case)] pub fn type__as_static_(&self) -> Option> { @@ -103,7 +108,6 @@ impl<'a> Table2<'a> { None } } - } impl ::flatbuffers::Verifiable for Table2<'_> { @@ -123,10 +127,12 @@ impl ::flatbuffers::Verifiable for Table2<'_> { Ok(()) } } + pub struct Table2Args { pub type_type: KeywordsInUnion, pub type_: Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>>, } + impl<'a> Default for Table2Args { #[inline] fn default() -> Self { @@ -141,15 +147,18 @@ pub struct Table2Builder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> Table2Builder<'a, 'b, A> { #[inline] pub fn add_type_type(&mut self, type_type: KeywordsInUnion) { self.fbb_.push_slot::(Table2::VT_TYPE_TYPE, type_type, KeywordsInUnion::NONE); } + #[inline] pub fn add_type_(&mut self, type_: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Table2::VT_TYPE_, type_); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> Table2Builder<'a, 'b, A> { let start = _fbb.start_table(); @@ -158,6 +167,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> Table2Builder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -192,11 +202,13 @@ impl ::core::fmt::Debug for Table2<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct Table2T { pub type_: KeywordsInUnionT, } + impl Default for Table2T { fn default() -> Self { Self { @@ -204,6 +216,7 @@ impl Default for Table2T { } } } + impl Table2T { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, diff --git a/tests/monster_test/my_game/example/ability_generated.rs b/tests/monster_test/my_game/example/ability_generated.rs index add3b470196..6cd6f901fb8 100644 --- a/tests/monster_test/my_game/example/ability_generated.rs +++ b/tests/monster_test/my_game/example/ability_generated.rs @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct Ability, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Ability(pub [u8; 8]); + impl Default for Ability { fn default() -> Self { Self([0; 8]) } } + impl ::core::fmt::Debug for Ability { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Ability") @@ -21,27 +24,34 @@ impl ::core::fmt::Debug for Ability { } impl ::flatbuffers::SimpleToVerifyInSlice for Ability {} + impl<'a> ::flatbuffers::Follow<'a> for Ability { type Inner = &'a Ability; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Ability>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Ability { type Inner = &'a Ability; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Ability { type Output = Ability; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Ability as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -102,6 +112,7 @@ impl<'a> Ability { } } + #[inline] pub fn key_compare_less_than(&self, o: &Ability) -> bool { self.id() < o.id() @@ -154,6 +165,7 @@ pub struct AbilityT { pub id: u32, pub distance: u32, } + impl AbilityT { pub fn pack(&self) -> Ability { Ability::new( @@ -162,4 +174,3 @@ impl AbilityT { ) } } - 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..1363d0e37bc 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 @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ANY_AMBIGUOUS_ALIASES: u8 = 3; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ANY_AMBIGUOUS_ALIASES: [AnyAmbiguousAliases; 4] = [ @@ -18,6 +21,7 @@ pub const ENUM_VALUES_ANY_AMBIGUOUS_ALIASES: [AnyAmbiguousAliases; 4] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct AnyAmbiguousAliases(pub u8); + #[allow(non_upper_case_globals)] impl AnyAmbiguousAliases { pub const NONE: Self = Self(0); @@ -33,6 +37,7 @@ impl AnyAmbiguousAliases { Self::M2, Self::M3, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -44,6 +49,7 @@ impl AnyAmbiguousAliases { } } } + impl ::core::fmt::Debug for AnyAmbiguousAliases { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -53,8 +59,10 @@ impl ::core::fmt::Debug for AnyAmbiguousAliases { } } } + impl<'a> ::flatbuffers::Follow<'a> for AnyAmbiguousAliases { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -64,6 +72,7 @@ impl<'a> ::flatbuffers::Follow<'a> for AnyAmbiguousAliases { impl ::flatbuffers::Push for AnyAmbiguousAliases { type Output = AnyAmbiguousAliases; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -72,10 +81,12 @@ impl ::flatbuffers::Push for AnyAmbiguousAliases { impl ::flatbuffers::EndianScalar for AnyAmbiguousAliases { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -94,6 +105,7 @@ impl<'a> ::flatbuffers::Verifiable for AnyAmbiguousAliases { } impl ::flatbuffers::SimpleToVerifyInSlice for AnyAmbiguousAliases {} + pub struct AnyAmbiguousAliasesUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -105,11 +117,13 @@ pub enum AnyAmbiguousAliasesT { M2(alloc::boxed::Box), M3(alloc::boxed::Box), } + impl Default for AnyAmbiguousAliasesT { fn default() -> Self { Self::NONE } } + impl AnyAmbiguousAliasesT { pub fn any_ambiguous_aliases_type(&self) -> AnyAmbiguousAliases { match self { @@ -119,6 +133,7 @@ impl AnyAmbiguousAliasesT { Self::M3(_) => AnyAmbiguousAliases::M3, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, @@ -127,6 +142,7 @@ impl AnyAmbiguousAliasesT { Self::M3(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m1(&mut self) -> Option> { if let Self::M1(_) = self { @@ -140,14 +156,17 @@ impl AnyAmbiguousAliasesT { None } } + /// If the union variant matches, return a reference to the MonsterT. pub fn as_m1(&self) -> Option<&MonsterT> { if let Self::M1(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the MonsterT. pub fn as_m1_mut(&mut self) -> Option<&mut MonsterT> { 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> { if let Self::M2(_) = self { @@ -161,14 +180,17 @@ impl AnyAmbiguousAliasesT { None } } + /// If the union variant matches, return a reference to the MonsterT. pub fn as_m2(&self) -> Option<&MonsterT> { if let Self::M2(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the MonsterT. pub fn as_m2_mut(&mut self) -> Option<&mut MonsterT> { 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> { if let Self::M3(_) = self { @@ -182,12 +204,15 @@ impl AnyAmbiguousAliasesT { None } } + /// If the union variant matches, return a reference to the MonsterT. pub fn as_m3(&self) -> Option<&MonsterT> { if let Self::M3(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the MonsterT. pub fn as_m3_mut(&mut self) -> Option<&mut MonsterT> { if let Self::M3(v) = self { Some(v.as_mut()) } else { None } } } + diff --git a/tests/monster_test/my_game/example/any_generated.rs b/tests/monster_test/my_game/example/any_generated.rs index a1da43781a6..268d316f67b 100644 --- a/tests/monster_test/my_game/example/any_generated.rs +++ b/tests/monster_test/my_game/example/any_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ANY: u8 = 3; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ANY: [Any; 4] = [ @@ -18,6 +21,7 @@ pub const ENUM_VALUES_ANY: [Any; 4] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Any(pub u8); + #[allow(non_upper_case_globals)] impl Any { pub const NONE: Self = Self(0); @@ -33,6 +37,7 @@ impl Any { Self::TestSimpleTableWithEnum, Self::MyGame_Example2_Monster, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -44,6 +49,7 @@ impl Any { } } } + impl ::core::fmt::Debug for Any { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -53,8 +59,10 @@ impl ::core::fmt::Debug for Any { } } } + impl<'a> ::flatbuffers::Follow<'a> for Any { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -64,6 +72,7 @@ impl<'a> ::flatbuffers::Follow<'a> for Any { impl ::flatbuffers::Push for Any { type Output = Any; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -72,10 +81,12 @@ impl ::flatbuffers::Push for Any { impl ::flatbuffers::EndianScalar for Any { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -94,6 +105,7 @@ impl<'a> ::flatbuffers::Verifiable for Any { } impl ::flatbuffers::SimpleToVerifyInSlice for Any {} + pub struct AnyUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -105,11 +117,13 @@ pub enum AnyT { TestSimpleTableWithEnum(alloc::boxed::Box), MyGameExample2Monster(alloc::boxed::Box), } + impl Default for AnyT { fn default() -> Self { Self::NONE } } + impl AnyT { pub fn any_type(&self) -> Any { match self { @@ -119,6 +133,7 @@ impl AnyT { Self::MyGameExample2Monster(_) => Any::MyGame_Example2_Monster, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, @@ -127,6 +142,7 @@ impl AnyT { Self::MyGameExample2Monster(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_monster(&mut self) -> Option> { if let Self::Monster(_) = self { @@ -140,14 +156,17 @@ impl AnyT { None } } + /// If the union variant matches, return a reference to the MonsterT. pub fn as_monster(&self) -> Option<&MonsterT> { if let Self::Monster(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the MonsterT. pub fn as_monster_mut(&mut self) -> Option<&mut MonsterT> { 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> { if let Self::TestSimpleTableWithEnum(_) = self { @@ -161,14 +180,17 @@ impl AnyT { None } } + /// If the union variant matches, return a reference to the TestSimpleTableWithEnumT. pub fn as_test_simple_table_with_enum(&self) -> Option<&TestSimpleTableWithEnumT> { if let Self::TestSimpleTableWithEnum(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the TestSimpleTableWithEnumT. pub fn as_test_simple_table_with_enum_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT> { 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> { if let Self::MyGameExample2Monster(_) = self { @@ -182,12 +204,15 @@ impl AnyT { None } } + /// If the union variant matches, return a reference to the super::example_2::MonsterT. pub fn as_my_game_example_2_monster(&self) -> Option<&super::example_2::MonsterT> { if let Self::MyGameExample2Monster(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the super::example_2::MonsterT. pub fn as_my_game_example_2_monster_mut(&mut self) -> Option<&mut super::example_2::MonsterT> { if let Self::MyGameExample2Monster(v) = self { Some(v.as_mut()) } else { None } } } + 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..f4d8592ba09 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 @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ANY_UNIQUE_ALIASES: u8 = 3; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ANY_UNIQUE_ALIASES: [AnyUniqueAliases; 4] = [ @@ -18,6 +21,7 @@ pub const ENUM_VALUES_ANY_UNIQUE_ALIASES: [AnyUniqueAliases; 4] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct AnyUniqueAliases(pub u8); + #[allow(non_upper_case_globals)] impl AnyUniqueAliases { pub const NONE: Self = Self(0); @@ -33,6 +37,7 @@ impl AnyUniqueAliases { Self::TS, Self::M2, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -44,6 +49,7 @@ impl AnyUniqueAliases { } } } + impl ::core::fmt::Debug for AnyUniqueAliases { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -53,8 +59,10 @@ impl ::core::fmt::Debug for AnyUniqueAliases { } } } + impl<'a> ::flatbuffers::Follow<'a> for AnyUniqueAliases { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -64,6 +72,7 @@ impl<'a> ::flatbuffers::Follow<'a> for AnyUniqueAliases { impl ::flatbuffers::Push for AnyUniqueAliases { type Output = AnyUniqueAliases; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -72,10 +81,12 @@ impl ::flatbuffers::Push for AnyUniqueAliases { impl ::flatbuffers::EndianScalar for AnyUniqueAliases { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -94,6 +105,7 @@ impl<'a> ::flatbuffers::Verifiable for AnyUniqueAliases { } impl ::flatbuffers::SimpleToVerifyInSlice for AnyUniqueAliases {} + pub struct AnyUniqueAliasesUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -105,11 +117,13 @@ pub enum AnyUniqueAliasesT { TS(alloc::boxed::Box), M2(alloc::boxed::Box), } + impl Default for AnyUniqueAliasesT { fn default() -> Self { Self::NONE } } + impl AnyUniqueAliasesT { pub fn any_unique_aliases_type(&self) -> AnyUniqueAliases { match self { @@ -119,6 +133,7 @@ impl AnyUniqueAliasesT { Self::M2(_) => AnyUniqueAliases::M2, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, @@ -127,6 +142,7 @@ impl AnyUniqueAliasesT { Self::M2(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m(&mut self) -> Option> { if let Self::M(_) = self { @@ -140,14 +156,17 @@ impl AnyUniqueAliasesT { None } } + /// If the union variant matches, return a reference to the MonsterT. pub fn as_m(&self) -> Option<&MonsterT> { if let Self::M(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the MonsterT. pub fn as_m_mut(&mut self) -> Option<&mut MonsterT> { 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> { if let Self::TS(_) = self { @@ -161,14 +180,17 @@ impl AnyUniqueAliasesT { None } } + /// If the union variant matches, return a reference to the TestSimpleTableWithEnumT. pub fn as_ts(&self) -> Option<&TestSimpleTableWithEnumT> { if let Self::TS(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the TestSimpleTableWithEnumT. pub fn as_ts_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT> { 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> { if let Self::M2(_) = self { @@ -182,12 +204,15 @@ impl AnyUniqueAliasesT { None } } + /// If the union variant matches, return a reference to the super::example_2::MonsterT. pub fn as_m2(&self) -> Option<&super::example_2::MonsterT> { if let Self::M2(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the super::example_2::MonsterT. pub fn as_m2_mut(&mut self) -> Option<&mut super::example_2::MonsterT> { if let Self::M2(v) = self { Some(v.as_mut()) } else { None } } } + diff --git a/tests/monster_test/my_game/example/color_generated.rs b/tests/monster_test/my_game/example/color_generated.rs index 5bade500f62..c4b584210ea 100644 --- a/tests/monster_test/my_game/example/color_generated.rs +++ b/tests/monster_test/my_game/example/color_generated.rs @@ -2,6 +2,7 @@ // @generated extern crate alloc; use super::*; + #[allow(non_upper_case_globals)] mod bitflags_color { ::flatbuffers::bitflags::bitflags! { @@ -17,10 +18,12 @@ mod bitflags_color { } } } + pub use self::bitflags_color::Color; impl<'a> ::flatbuffers::Follow<'a> for Color { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -30,6 +33,7 @@ impl<'a> ::flatbuffers::Follow<'a> for Color { impl ::flatbuffers::Push for Color { type Output = Color; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.bits()) }; @@ -38,10 +42,12 @@ impl ::flatbuffers::Push for Color { impl ::flatbuffers::EndianScalar for Color { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.bits().to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { 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..b690f44c89e 100644 --- a/tests/monster_test/my_game/example/long_enum_generated.rs +++ b/tests/monster_test/my_game/example/long_enum_generated.rs @@ -2,6 +2,7 @@ // @generated extern crate alloc; use super::*; + #[allow(non_upper_case_globals)] mod bitflags_long_enum { ::flatbuffers::bitflags::bitflags! { @@ -13,10 +14,12 @@ mod bitflags_long_enum { } } } + pub use self::bitflags_long_enum::LongEnum; impl<'a> ::flatbuffers::Follow<'a> for LongEnum { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -26,6 +29,7 @@ impl<'a> ::flatbuffers::Follow<'a> for LongEnum { impl ::flatbuffers::Push for LongEnum { type Output = LongEnum; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.bits()) }; @@ -34,10 +38,12 @@ impl ::flatbuffers::Push for LongEnum { impl ::flatbuffers::EndianScalar for LongEnum { type Scalar = u64; + #[inline] fn to_little_endian(self) -> u64 { self.bits().to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u64) -> Self { diff --git a/tests/monster_test/my_game/example/monster_generated.rs b/tests/monster_test/my_game/example/monster_generated.rs index db44ea51d9f..34aaac631fd 100644 --- a/tests/monster_test/my_game/example/monster_generated.rs +++ b/tests/monster_test/my_game/example/monster_generated.rs @@ -2,16 +2,18 @@ // @generated extern crate alloc; use super::*; + pub enum MonsterOffset {} -#[derive(Copy, Clone, PartialEq)] /// an example documentation comment: "monster object" +#[derive(Copy, Clone, PartialEq)] pub struct Monster<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Monster<'a> { type Inner = Monster<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -89,6 +91,7 @@ impl<'a> Monster<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Monster { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -394,6 +397,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_POS, None)} } + #[inline] pub fn mana(&self) -> i16 { // Safety: @@ -401,6 +405,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_MANA, Some(150)).unwrap()} } + #[inline] pub fn hp(&self) -> i16 { // Safety: @@ -408,6 +413,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_HP, Some(100)).unwrap()} } + #[inline] pub fn name(&self) -> &'a str { // Safety: @@ -415,6 +421,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()} } + #[inline] pub fn key_compare_less_than(&self, o: &Monster) -> bool { self.name() < o.name() @@ -425,6 +432,7 @@ impl<'a> Monster<'a> { let key = self.name(); key.cmp(val) } + #[inline] pub fn inventory(&self) -> Option<::flatbuffers::Vector<'a, u8>> { // Safety: @@ -432,6 +440,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None)} } + #[inline] pub fn color(&self) -> Color { // Safety: @@ -439,6 +448,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_COLOR, Some(Color::Blue)).unwrap()} } + #[inline] pub fn test_type(&self) -> Any { // Safety: @@ -446,6 +456,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TEST_TYPE, Some(Any::NONE)).unwrap()} } + #[inline] pub fn test(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -453,6 +464,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(Monster::VT_TEST, None)} } + #[inline] pub fn test4(&self) -> Option<::flatbuffers::Vector<'a, Test>> { // Safety: @@ -460,6 +472,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST4, None)} } + #[inline] pub fn testarrayofstring(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<&'a str>>> { // Safety: @@ -467,6 +480,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING, None)} } + /// an example documentation comment: this will end up in the generated code /// multiline too #[inline] @@ -476,6 +490,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Monster::VT_TESTARRAYOFTABLES, None)} } + #[inline] pub fn enemy(&self) -> Option> { // Safety: @@ -483,6 +498,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(Monster::VT_ENEMY, None)} } + #[inline] pub fn testnestedflatbuffer(&self) -> Option<::flatbuffers::Vector<'a, u8>> { // Safety: @@ -490,6 +506,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTNESTEDFLATBUFFER, None)} } + pub fn testnestedflatbuffer_nested_flatbuffer(&'a self) -> Option> { self.testnestedflatbuffer().map(|data| { use ::flatbuffers::Follow; @@ -499,6 +516,7 @@ impl<'a> Monster<'a> { unsafe { <::flatbuffers::ForwardsUOffset>>::follow(data.bytes(), 0) } }) } + #[inline] pub fn testempty(&self) -> Option> { // Safety: @@ -506,6 +524,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(Monster::VT_TESTEMPTY, None)} } + #[inline] pub fn testbool(&self) -> bool { // Safety: @@ -513,6 +532,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTBOOL, Some(false)).unwrap()} } + #[inline] pub fn testhashs32_fnv1(&self) -> i32 { // Safety: @@ -520,6 +540,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHS32_FNV1, Some(0)).unwrap()} } + #[inline] pub fn testhashu32_fnv1(&self) -> u32 { // Safety: @@ -527,6 +548,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHU32_FNV1, Some(0)).unwrap()} } + #[inline] pub fn testhashs64_fnv1(&self) -> i64 { // Safety: @@ -534,6 +556,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHS64_FNV1, Some(0)).unwrap()} } + #[inline] pub fn testhashu64_fnv1(&self) -> u64 { // Safety: @@ -541,6 +564,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHU64_FNV1, Some(0)).unwrap()} } + #[inline] pub fn testhashs32_fnv1a(&self) -> i32 { // Safety: @@ -548,6 +572,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHS32_FNV1A, Some(0)).unwrap()} } + #[inline] pub fn testhashu32_fnv1a(&self) -> u32 { // Safety: @@ -555,6 +580,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHU32_FNV1A, Some(0)).unwrap()} } + #[inline] pub fn testhashs64_fnv1a(&self) -> i64 { // Safety: @@ -562,6 +588,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHS64_FNV1A, Some(0)).unwrap()} } + #[inline] pub fn testhashu64_fnv1a(&self) -> u64 { // Safety: @@ -569,6 +596,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHU64_FNV1A, Some(0)).unwrap()} } + #[inline] pub fn testarrayofbools(&self) -> Option<::flatbuffers::Vector<'a, bool>> { // Safety: @@ -576,6 +604,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, bool>>>(Monster::VT_TESTARRAYOFBOOLS, None)} } + #[inline] pub fn testf(&self) -> f32 { // Safety: @@ -583,6 +612,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTF, Some(3.14159)).unwrap()} } + #[inline] pub fn testf2(&self) -> f32 { // Safety: @@ -590,6 +620,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTF2, Some(3.0)).unwrap()} } + #[inline] pub fn testf3(&self) -> f32 { // Safety: @@ -597,6 +628,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTF3, Some(0.0)).unwrap()} } + #[inline] pub fn testarrayofstring2(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<&'a str>>> { // Safety: @@ -604,6 +636,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING2, None)} } + #[inline] pub fn testarrayofsortedstruct(&self) -> Option<::flatbuffers::Vector<'a, Ability>> { // Safety: @@ -611,6 +644,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, Ability>>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, None)} } + #[inline] pub fn flex(&self) -> Option<::flatbuffers::Vector<'a, u8>> { // Safety: @@ -618,6 +652,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u8>>>(Monster::VT_FLEX, None)} } + #[inline] pub fn test5(&self) -> Option<::flatbuffers::Vector<'a, Test>> { // Safety: @@ -625,6 +660,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST5, None)} } + #[inline] pub fn vector_of_longs(&self) -> Option<::flatbuffers::Vector<'a, i64>> { // Safety: @@ -632,6 +668,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, i64>>>(Monster::VT_VECTOR_OF_LONGS, None)} } + #[inline] pub fn vector_of_doubles(&self) -> Option<::flatbuffers::Vector<'a, f64>> { // Safety: @@ -639,6 +676,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, f64>>>(Monster::VT_VECTOR_OF_DOUBLES, None)} } + #[inline] pub fn parent_namespace_test(&self) -> Option> { // Safety: @@ -646,6 +684,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(Monster::VT_PARENT_NAMESPACE_TEST, None)} } + #[inline] pub fn vector_of_referrables(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>> { // Safety: @@ -653,6 +692,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Monster::VT_VECTOR_OF_REFERRABLES, None)} } + #[inline] pub fn single_weak_reference(&self) -> u64 { // Safety: @@ -660,6 +700,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_SINGLE_WEAK_REFERENCE, Some(0)).unwrap()} } + #[inline] pub fn vector_of_weak_references(&self) -> Option<::flatbuffers::Vector<'a, u64>> { // Safety: @@ -667,6 +708,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, None)} } + #[inline] pub fn vector_of_strong_referrables(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>> { // Safety: @@ -674,6 +716,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, None)} } + #[inline] pub fn co_owning_reference(&self) -> u64 { // Safety: @@ -681,6 +724,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_CO_OWNING_REFERENCE, Some(0)).unwrap()} } + #[inline] pub fn vector_of_co_owning_references(&self) -> Option<::flatbuffers::Vector<'a, u64>> { // Safety: @@ -688,6 +732,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, None)} } + #[inline] pub fn non_owning_reference(&self) -> u64 { // Safety: @@ -695,6 +740,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_NON_OWNING_REFERENCE, Some(0)).unwrap()} } + #[inline] pub fn vector_of_non_owning_references(&self) -> Option<::flatbuffers::Vector<'a, u64>> { // Safety: @@ -702,6 +748,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, None)} } + #[inline] pub fn any_unique_type(&self) -> AnyUniqueAliases { // Safety: @@ -709,6 +756,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_ANY_UNIQUE_TYPE, Some(AnyUniqueAliases::NONE)).unwrap()} } + #[inline] pub fn any_unique(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -716,6 +764,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(Monster::VT_ANY_UNIQUE, None)} } + #[inline] pub fn any_ambiguous_type(&self) -> AnyAmbiguousAliases { // Safety: @@ -723,6 +772,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_ANY_AMBIGUOUS_TYPE, Some(AnyAmbiguousAliases::NONE)).unwrap()} } + #[inline] pub fn any_ambiguous(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -730,6 +780,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(Monster::VT_ANY_AMBIGUOUS, None)} } + #[inline] pub fn vector_of_enums(&self) -> Option<::flatbuffers::Vector<'a, Color>> { // Safety: @@ -737,6 +788,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)} } + #[inline] pub fn signed_enum(&self) -> Race { // Safety: @@ -744,6 +796,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()} } + #[inline] pub fn testrequirednestedflatbuffer(&self) -> Option<::flatbuffers::Vector<'a, u8>> { // Safety: @@ -751,6 +804,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, None)} } + pub fn testrequirednestedflatbuffer_nested_flatbuffer(&'a self) -> Option> { self.testrequirednestedflatbuffer().map(|data| { use ::flatbuffers::Follow; @@ -760,6 +814,7 @@ impl<'a> Monster<'a> { unsafe { <::flatbuffers::ForwardsUOffset>>::follow(data.bytes(), 0) } }) } + #[inline] pub fn scalar_key_sorted_tables(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>> { // Safety: @@ -767,6 +822,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, None)} } + #[inline] pub fn native_inline(&self) -> Option<&'a Test> { // Safety: @@ -774,6 +830,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_NATIVE_INLINE, None)} } + #[inline] pub fn long_enum_non_enum_default(&self) -> LongEnum { // Safety: @@ -781,6 +838,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, Some(Default::default())).unwrap()} } + #[inline] pub fn long_enum_normal_default(&self) -> LongEnum { // Safety: @@ -788,6 +846,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, Some(LongEnum::LongOne)).unwrap()} } + #[inline] pub fn nan_default(&self) -> f32 { // Safety: @@ -795,6 +854,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_NAN_DEFAULT, Some(f32::NAN)).unwrap()} } + #[inline] pub fn inf_default(&self) -> f32 { // Safety: @@ -802,6 +862,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_INF_DEFAULT, Some(f32::INFINITY)).unwrap()} } + #[inline] pub fn positive_inf_default(&self) -> f32 { // Safety: @@ -809,6 +870,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_POSITIVE_INF_DEFAULT, Some(f32::INFINITY)).unwrap()} } + #[inline] pub fn infinity_default(&self) -> f32 { // Safety: @@ -816,6 +878,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_INFINITY_DEFAULT, Some(f32::INFINITY)).unwrap()} } + #[inline] pub fn positive_infinity_default(&self) -> f32 { // Safety: @@ -823,6 +886,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_POSITIVE_INFINITY_DEFAULT, Some(f32::INFINITY)).unwrap()} } + #[inline] pub fn negative_inf_default(&self) -> f32 { // Safety: @@ -830,6 +894,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_NEGATIVE_INF_DEFAULT, Some(f32::NEG_INFINITY)).unwrap()} } + #[inline] pub fn negative_infinity_default(&self) -> f32 { // Safety: @@ -837,6 +902,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_NEGATIVE_INFINITY_DEFAULT, Some(f32::NEG_INFINITY)).unwrap()} } + #[inline] pub fn double_inf_default(&self) -> f64 { // Safety: @@ -844,6 +910,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_DOUBLE_INF_DEFAULT, Some(f64::INFINITY)).unwrap()} } + #[inline] #[allow(non_snake_case)] pub fn test_as_monster(&self) -> Option> { @@ -978,7 +1045,6 @@ impl<'a> Monster<'a> { None } } - } impl ::flatbuffers::Verifiable for Monster<'_> { @@ -1070,6 +1136,7 @@ impl ::flatbuffers::Verifiable for Monster<'_> { Ok(()) } } + pub struct MonsterArgs<'a> { pub pos: Option<&'a Vec3>, pub mana: i16, @@ -1133,6 +1200,7 @@ pub struct MonsterArgs<'a> { pub negative_infinity_default: f32, pub double_inf_default: f64, } + impl<'a> Default for MonsterArgs<'a> { #[inline] fn default() -> Self { @@ -1206,251 +1274,313 @@ pub struct MonsterBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> { #[inline] pub fn add_pos(&mut self, pos: &Vec3) { self.fbb_.push_slot_always::<&Vec3>(Monster::VT_POS, pos); } + #[inline] pub fn add_mana(&mut self, mana: i16) { self.fbb_.push_slot::(Monster::VT_MANA, mana, 150); } + #[inline] pub fn add_hp(&mut self, hp: i16) { self.fbb_.push_slot::(Monster::VT_HP, hp, 100); } + #[inline] pub fn add_name(&mut self, name: ::flatbuffers::WIPOffset<&'b str>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_NAME, name); } + #[inline] pub fn add_inventory(&mut self, inventory: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_INVENTORY, inventory); } + #[inline] pub fn add_color(&mut self, color: Color) { self.fbb_.push_slot::(Monster::VT_COLOR, color, Color::Blue); } + #[inline] pub fn add_test_type(&mut self, test_type: Any) { self.fbb_.push_slot::(Monster::VT_TEST_TYPE, test_type, Any::NONE); } + #[inline] pub fn add_test(&mut self, test: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TEST, test); } + #[inline] pub fn add_test4(&mut self, test4: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , Test>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TEST4, test4); } + #[inline] pub fn add_testarrayofstring(&mut self, testarrayofstring: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset<&'b str>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTARRAYOFSTRING, testarrayofstring); } + #[inline] pub fn add_testarrayoftables(&mut self, testarrayoftables: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTARRAYOFTABLES, testarrayoftables); } + #[inline] pub fn add_enemy(&mut self, enemy: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(Monster::VT_ENEMY, enemy); } + #[inline] pub fn add_testnestedflatbuffer(&mut self, testnestedflatbuffer: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTNESTEDFLATBUFFER, testnestedflatbuffer); } + #[inline] pub fn add_testempty(&mut self, testempty: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(Monster::VT_TESTEMPTY, testempty); } + #[inline] pub fn add_testbool(&mut self, testbool: bool) { self.fbb_.push_slot::(Monster::VT_TESTBOOL, testbool, false); } + #[inline] pub fn add_testhashs32_fnv1(&mut self, testhashs32_fnv1: i32) { self.fbb_.push_slot::(Monster::VT_TESTHASHS32_FNV1, testhashs32_fnv1, 0); } + #[inline] pub fn add_testhashu32_fnv1(&mut self, testhashu32_fnv1: u32) { self.fbb_.push_slot::(Monster::VT_TESTHASHU32_FNV1, testhashu32_fnv1, 0); } + #[inline] pub fn add_testhashs64_fnv1(&mut self, testhashs64_fnv1: i64) { self.fbb_.push_slot::(Monster::VT_TESTHASHS64_FNV1, testhashs64_fnv1, 0); } + #[inline] pub fn add_testhashu64_fnv1(&mut self, testhashu64_fnv1: u64) { self.fbb_.push_slot::(Monster::VT_TESTHASHU64_FNV1, testhashu64_fnv1, 0); } + #[inline] pub fn add_testhashs32_fnv1a(&mut self, testhashs32_fnv1a: i32) { self.fbb_.push_slot::(Monster::VT_TESTHASHS32_FNV1A, testhashs32_fnv1a, 0); } + #[inline] pub fn add_testhashu32_fnv1a(&mut self, testhashu32_fnv1a: u32) { self.fbb_.push_slot::(Monster::VT_TESTHASHU32_FNV1A, testhashu32_fnv1a, 0); } + #[inline] pub fn add_testhashs64_fnv1a(&mut self, testhashs64_fnv1a: i64) { self.fbb_.push_slot::(Monster::VT_TESTHASHS64_FNV1A, testhashs64_fnv1a, 0); } + #[inline] pub fn add_testhashu64_fnv1a(&mut self, testhashu64_fnv1a: u64) { self.fbb_.push_slot::(Monster::VT_TESTHASHU64_FNV1A, testhashu64_fnv1a, 0); } + #[inline] pub fn add_testarrayofbools(&mut self, testarrayofbools: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , bool>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTARRAYOFBOOLS, testarrayofbools); } + #[inline] pub fn add_testf(&mut self, testf: f32) { self.fbb_.push_slot::(Monster::VT_TESTF, testf, 3.14159); } + #[inline] pub fn add_testf2(&mut self, testf2: f32) { self.fbb_.push_slot::(Monster::VT_TESTF2, testf2, 3.0); } + #[inline] pub fn add_testf3(&mut self, testf3: f32) { self.fbb_.push_slot::(Monster::VT_TESTF3, testf3, 0.0); } + #[inline] pub fn add_testarrayofstring2(&mut self, testarrayofstring2: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset<&'b str>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTARRAYOFSTRING2, testarrayofstring2); } + #[inline] pub fn add_testarrayofsortedstruct(&mut self, testarrayofsortedstruct: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , Ability>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, testarrayofsortedstruct); } + #[inline] pub fn add_flex(&mut self, flex: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_FLEX, flex); } + #[inline] pub fn add_test5(&mut self, test5: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , Test>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TEST5, test5); } + #[inline] pub fn add_vector_of_longs(&mut self, vector_of_longs: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , i64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_LONGS, vector_of_longs); } + #[inline] pub fn add_vector_of_doubles(&mut self, vector_of_doubles: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , f64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_DOUBLES, vector_of_doubles); } + #[inline] pub fn add_parent_namespace_test(&mut self, parent_namespace_test: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(Monster::VT_PARENT_NAMESPACE_TEST, parent_namespace_test); } + #[inline] pub fn add_vector_of_referrables(&mut self, vector_of_referrables: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_REFERRABLES, vector_of_referrables); } + #[inline] pub fn add_single_weak_reference(&mut self, single_weak_reference: u64) { self.fbb_.push_slot::(Monster::VT_SINGLE_WEAK_REFERENCE, single_weak_reference, 0); } + #[inline] pub fn add_vector_of_weak_references(&mut self, vector_of_weak_references: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, vector_of_weak_references); } + #[inline] pub fn add_vector_of_strong_referrables(&mut self, vector_of_strong_referrables: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, vector_of_strong_referrables); } + #[inline] pub fn add_co_owning_reference(&mut self, co_owning_reference: u64) { self.fbb_.push_slot::(Monster::VT_CO_OWNING_REFERENCE, co_owning_reference, 0); } + #[inline] pub fn add_vector_of_co_owning_references(&mut self, vector_of_co_owning_references: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, vector_of_co_owning_references); } + #[inline] pub fn add_non_owning_reference(&mut self, non_owning_reference: u64) { self.fbb_.push_slot::(Monster::VT_NON_OWNING_REFERENCE, non_owning_reference, 0); } + #[inline] pub fn add_vector_of_non_owning_references(&mut self, vector_of_non_owning_references: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, vector_of_non_owning_references); } + #[inline] pub fn add_any_unique_type(&mut self, any_unique_type: AnyUniqueAliases) { self.fbb_.push_slot::(Monster::VT_ANY_UNIQUE_TYPE, any_unique_type, AnyUniqueAliases::NONE); } + #[inline] pub fn add_any_unique(&mut self, any_unique: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_ANY_UNIQUE, any_unique); } + #[inline] pub fn add_any_ambiguous_type(&mut self, any_ambiguous_type: AnyAmbiguousAliases) { self.fbb_.push_slot::(Monster::VT_ANY_AMBIGUOUS_TYPE, any_ambiguous_type, AnyAmbiguousAliases::NONE); } + #[inline] pub fn add_any_ambiguous(&mut self, any_ambiguous: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_ANY_AMBIGUOUS, any_ambiguous); } + #[inline] pub fn add_vector_of_enums(&mut self, vector_of_enums: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , Color>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_ENUMS, vector_of_enums); } + #[inline] pub fn add_signed_enum(&mut self, signed_enum: Race) { self.fbb_.push_slot::(Monster::VT_SIGNED_ENUM, signed_enum, Race::None); } + #[inline] pub fn add_testrequirednestedflatbuffer(&mut self, testrequirednestedflatbuffer: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, testrequirednestedflatbuffer); } + #[inline] pub fn add_scalar_key_sorted_tables(&mut self, scalar_key_sorted_tables: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, scalar_key_sorted_tables); } + #[inline] pub fn add_native_inline(&mut self, native_inline: &Test) { self.fbb_.push_slot_always::<&Test>(Monster::VT_NATIVE_INLINE, native_inline); } + #[inline] pub fn add_long_enum_non_enum_default(&mut self, long_enum_non_enum_default: LongEnum) { self.fbb_.push_slot::(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, long_enum_non_enum_default, Default::default()); } + #[inline] pub fn add_long_enum_normal_default(&mut self, long_enum_normal_default: LongEnum) { self.fbb_.push_slot::(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, long_enum_normal_default, LongEnum::LongOne); } + #[inline] pub fn add_nan_default(&mut self, nan_default: f32) { self.fbb_.push_slot::(Monster::VT_NAN_DEFAULT, nan_default, f32::NAN); } + #[inline] pub fn add_inf_default(&mut self, inf_default: f32) { self.fbb_.push_slot::(Monster::VT_INF_DEFAULT, inf_default, f32::INFINITY); } + #[inline] pub fn add_positive_inf_default(&mut self, positive_inf_default: f32) { self.fbb_.push_slot::(Monster::VT_POSITIVE_INF_DEFAULT, positive_inf_default, f32::INFINITY); } + #[inline] pub fn add_infinity_default(&mut self, infinity_default: f32) { self.fbb_.push_slot::(Monster::VT_INFINITY_DEFAULT, infinity_default, f32::INFINITY); } + #[inline] pub fn add_positive_infinity_default(&mut self, positive_infinity_default: f32) { self.fbb_.push_slot::(Monster::VT_POSITIVE_INFINITY_DEFAULT, positive_infinity_default, f32::INFINITY); } + #[inline] pub fn add_negative_inf_default(&mut self, negative_inf_default: f32) { self.fbb_.push_slot::(Monster::VT_NEGATIVE_INF_DEFAULT, negative_inf_default, f32::NEG_INFINITY); } + #[inline] pub fn add_negative_infinity_default(&mut self, negative_infinity_default: f32) { self.fbb_.push_slot::(Monster::VT_NEGATIVE_INFINITY_DEFAULT, negative_infinity_default, f32::NEG_INFINITY); } + #[inline] pub fn add_double_inf_default(&mut self, double_inf_default: f64) { self.fbb_.push_slot::(Monster::VT_DOUBLE_INF_DEFAULT, double_inf_default, f64::INFINITY); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> MonsterBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -1459,6 +1589,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -1612,6 +1743,7 @@ impl ::core::fmt::Debug for Monster<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MonsterT { @@ -1674,6 +1806,7 @@ pub struct MonsterT { pub negative_infinity_default: f32, pub double_inf_default: f64, } + impl Default for MonsterT { fn default() -> Self { Self { @@ -1738,6 +1871,7 @@ impl Default for MonsterT { } } } + impl MonsterT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, @@ -1920,66 +2054,73 @@ impl MonsterT { }) } } -#[inline] + /// Verifies that a buffer of bytes contains a `Monster` /// and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. +#[inline] pub fn root_as_monster(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::root::(buf) } -#[inline] + /// Verifies that a buffer of bytes contains a size prefixed /// `Monster` and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_monster_unchecked`. +#[inline] pub fn size_prefixed_root_as_monster(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::size_prefixed_root::(buf) } -#[inline] + /// Verifies, with the given options, that a buffer of bytes /// contains a `Monster` and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. +#[inline] pub fn root_as_monster_with_opts<'b, 'o>( opts: &'o ::flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::root_with_opts::>(opts, buf) } -#[inline] + /// Verifies, with the given verifier options, that a buffer of /// bytes contains a size prefixed `Monster` and returns /// it. Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. +#[inline] pub fn size_prefixed_root_as_monster_with_opts<'b, 'o>( opts: &'o ::flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } -#[inline] + /// Assumes, without verification, that a buffer of bytes contains a Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `Monster`. +#[inline] pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { ::flatbuffers::root_unchecked::(buf) } } -#[inline] + /// Assumes, without verification, that a buffer of bytes contains a size prefixed Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `Monster`. +#[inline] pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { ::flatbuffers::size_prefixed_root_unchecked::(buf) } } + pub const MONSTER_IDENTIFIER: &str = "MONS"; #[inline] diff --git a/tests/monster_test/my_game/example/race_generated.rs b/tests/monster_test/my_game/example/race_generated.rs index 095647f31e2..013ceb33d0f 100644 --- a/tests/monster_test/my_game/example/race_generated.rs +++ b/tests/monster_test/my_game/example/race_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_RACE: i8 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_RACE: [Race; 4] = [ @@ -18,6 +21,7 @@ pub const ENUM_VALUES_RACE: [Race; 4] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Race(pub i8); + #[allow(non_upper_case_globals)] impl Race { pub const None: Self = Self(-1); @@ -33,6 +37,7 @@ impl Race { Self::Dwarf, Self::Elf, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -44,6 +49,7 @@ impl Race { } } } + impl ::core::fmt::Debug for Race { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -53,8 +59,10 @@ impl ::core::fmt::Debug for Race { } } } + impl<'a> ::flatbuffers::Follow<'a> for Race { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -64,6 +72,7 @@ impl<'a> ::flatbuffers::Follow<'a> for Race { impl ::flatbuffers::Push for Race { type Output = Race; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -72,10 +81,12 @@ impl ::flatbuffers::Push for Race { impl ::flatbuffers::EndianScalar for Race { type Scalar = i8; + #[inline] fn to_little_endian(self) -> i8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i8) -> Self { diff --git a/tests/monster_test/my_game/example/referrable_generated.rs b/tests/monster_test/my_game/example/referrable_generated.rs index 08e1f843f67..09832db42a7 100644 --- a/tests/monster_test/my_game/example/referrable_generated.rs +++ b/tests/monster_test/my_game/example/referrable_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum ReferrableOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct Referrable<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Referrable<'a> { type Inner = Referrable<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> Referrable<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Referrable { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -52,6 +55,7 @@ impl<'a> Referrable<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Referrable::VT_ID, Some(0)).unwrap()} } + #[inline] pub fn key_compare_less_than(&self, o: &Referrable) -> bool { self.id() < o.id() @@ -75,9 +79,11 @@ impl ::flatbuffers::Verifiable for Referrable<'_> { Ok(()) } } + pub struct ReferrableArgs { pub id: u64, } + impl<'a> Default for ReferrableArgs { #[inline] fn default() -> Self { @@ -91,11 +97,13 @@ pub struct ReferrableBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> ReferrableBuilder<'a, 'b, A> { #[inline] pub fn add_id(&mut self, id: u64) { self.fbb_.push_slot::(Referrable::VT_ID, id, 0); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> ReferrableBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -104,6 +112,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> ReferrableBuilder<'a, 'b, A> start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -118,11 +127,13 @@ impl ::core::fmt::Debug for Referrable<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct ReferrableT { pub id: u64, } + impl Default for ReferrableT { fn default() -> Self { Self { @@ -130,6 +141,7 @@ impl Default for ReferrableT { } } } + impl ReferrableT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, diff --git a/tests/monster_test/my_game/example/stat_generated.rs b/tests/monster_test/my_game/example/stat_generated.rs index 5f330356c9b..223631b6f03 100644 --- a/tests/monster_test/my_game/example/stat_generated.rs +++ b/tests/monster_test/my_game/example/stat_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum StatOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct Stat<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Stat<'a> { type Inner = Stat<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -30,6 +32,7 @@ impl<'a> Stat<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Stat { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -62,6 +65,7 @@ impl<'a> Stat<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)} } + #[inline] pub fn val(&self) -> i64 { // Safety: @@ -69,6 +73,7 @@ impl<'a> Stat<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Stat::VT_VAL, Some(0)).unwrap()} } + #[inline] pub fn count(&self) -> u16 { // Safety: @@ -76,6 +81,7 @@ impl<'a> Stat<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Stat::VT_COUNT, Some(0)).unwrap()} } + #[inline] pub fn key_compare_less_than(&self, o: &Stat) -> bool { self.count() < o.count() @@ -101,11 +107,13 @@ impl ::flatbuffers::Verifiable for Stat<'_> { Ok(()) } } + pub struct StatArgs<'a> { pub id: Option<::flatbuffers::WIPOffset<&'a str>>, pub val: i64, pub count: u16, } + impl<'a> Default for StatArgs<'a> { #[inline] fn default() -> Self { @@ -121,19 +129,23 @@ pub struct StatBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> StatBuilder<'a, 'b, A> { #[inline] pub fn add_id(&mut self, id: ::flatbuffers::WIPOffset<&'b str>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Stat::VT_ID, id); } + #[inline] pub fn add_val(&mut self, val: i64) { self.fbb_.push_slot::(Stat::VT_VAL, val, 0); } + #[inline] pub fn add_count(&mut self, count: u16) { self.fbb_.push_slot::(Stat::VT_COUNT, count, 0); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> StatBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -142,6 +154,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> StatBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -158,6 +171,7 @@ impl ::core::fmt::Debug for Stat<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct StatT { @@ -165,6 +179,7 @@ pub struct StatT { pub val: i64, pub count: u16, } + impl Default for StatT { fn default() -> Self { Self { @@ -174,6 +189,7 @@ impl Default for StatT { } } } + impl StatT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..b957d26b5d5 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 @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct StructOfStructs, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct StructOfStructs(pub [u8; 20]); + impl Default for StructOfStructs { fn default() -> Self { Self([0; 20]) } } + impl ::core::fmt::Debug for StructOfStructs { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("StructOfStructs") @@ -22,27 +25,34 @@ impl ::core::fmt::Debug for StructOfStructs { } impl ::flatbuffers::SimpleToVerifyInSlice for StructOfStructs {} + impl<'a> ::flatbuffers::Follow<'a> for StructOfStructs { type Inner = &'a StructOfStructs; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a StructOfStructs>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a StructOfStructs { type Inner = &'a StructOfStructs; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for StructOfStructs { type Output = StructOfStructs; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -127,6 +137,7 @@ pub struct StructOfStructsT { pub b: TestT, pub c: AbilityT, } + impl StructOfStructsT { pub fn pack(&self) -> StructOfStructs { StructOfStructs::new( @@ -136,4 +147,3 @@ impl StructOfStructsT { ) } } - 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..34a4832aea4 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 @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct StructOfStructsOfStructs, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct StructOfStructsOfStructs(pub [u8; 20]); + impl Default for StructOfStructsOfStructs { fn default() -> Self { Self([0; 20]) } } + impl ::core::fmt::Debug for StructOfStructsOfStructs { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("StructOfStructsOfStructs") @@ -20,27 +23,34 @@ impl ::core::fmt::Debug for StructOfStructsOfStructs { } impl ::flatbuffers::SimpleToVerifyInSlice for StructOfStructsOfStructs {} + impl<'a> ::flatbuffers::Follow<'a> for StructOfStructsOfStructs { type Inner = &'a StructOfStructsOfStructs; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a StructOfStructsOfStructs>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a StructOfStructsOfStructs { type Inner = &'a StructOfStructsOfStructs; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for StructOfStructsOfStructs { type Output = StructOfStructsOfStructs; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -93,6 +103,7 @@ impl<'a> StructOfStructsOfStructs { pub struct StructOfStructsOfStructsT { pub a: StructOfStructsT, } + impl StructOfStructsOfStructsT { pub fn pack(&self) -> StructOfStructsOfStructs { StructOfStructsOfStructs::new( @@ -100,4 +111,3 @@ impl StructOfStructsOfStructsT { ) } } - diff --git a/tests/monster_test/my_game/example/test_generated.rs b/tests/monster_test/my_game/example/test_generated.rs index 178cbe99c4e..a5984a9de00 100644 --- a/tests/monster_test/my_game/example/test_generated.rs +++ b/tests/monster_test/my_game/example/test_generated.rs @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct Test, aligned to 2 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Test(pub [u8; 4]); + impl Default for Test { fn default() -> Self { Self([0; 4]) } } + impl ::core::fmt::Debug for Test { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Test") @@ -21,27 +24,34 @@ impl ::core::fmt::Debug for Test { } impl ::flatbuffers::SimpleToVerifyInSlice for Test {} + impl<'a> ::flatbuffers::Follow<'a> for Test { type Inner = &'a Test; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Test>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Test { type Inner = &'a Test; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Test { type Output = Test; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Test as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(2) @@ -144,6 +154,7 @@ pub struct TestT { pub a: i16, pub b: i8, } + impl TestT { pub fn pack(&self) -> Test { Test::new( @@ -152,4 +163,3 @@ impl TestT { ) } } - 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..d00ad65ff04 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TestSimpleTableWithEnumOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TestSimpleTableWithEnum<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> { type Inner = TestSimpleTableWithEnum<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> TestSimpleTableWithEnum<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TestSimpleTableWithEnum { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -65,9 +68,11 @@ impl ::flatbuffers::Verifiable for TestSimpleTableWithEnum<'_> { Ok(()) } } + pub struct TestSimpleTableWithEnumArgs { pub color: Color, } + impl<'a> Default for TestSimpleTableWithEnumArgs { #[inline] fn default() -> Self { @@ -81,11 +86,13 @@ pub struct TestSimpleTableWithEnumBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocato fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TestSimpleTableWithEnumBuilder<'a, 'b, A> { #[inline] pub fn add_color(&mut self, color: Color) { self.fbb_.push_slot::(TestSimpleTableWithEnum::VT_COLOR, color, Color::Green); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TestSimpleTableWithEnumBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -94,6 +101,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TestSimpleTableWithEnumBuilde start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -108,11 +116,13 @@ impl ::core::fmt::Debug for TestSimpleTableWithEnum<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TestSimpleTableWithEnumT { pub color: Color, } + impl Default for TestSimpleTableWithEnumT { fn default() -> Self { Self { @@ -120,6 +130,7 @@ impl Default for TestSimpleTableWithEnumT { } } } + impl TestSimpleTableWithEnumT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..9ef6c101a09 100644 --- a/tests/monster_test/my_game/example/type_aliases_generated.rs +++ b/tests/monster_test/my_game/example/type_aliases_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TypeAliasesOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TypeAliases<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TypeAliases<'a> { type Inner = TypeAliases<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -39,6 +41,7 @@ impl<'a> TypeAliases<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TypeAliases { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -100,6 +103,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_I8_, Some(0)).unwrap()} } + #[inline] pub fn u8_(&self) -> u8 { // Safety: @@ -107,6 +111,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_U8_, Some(0)).unwrap()} } + #[inline] pub fn i16_(&self) -> i16 { // Safety: @@ -114,6 +119,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_I16_, Some(0)).unwrap()} } + #[inline] pub fn u16_(&self) -> u16 { // Safety: @@ -121,6 +127,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_U16_, Some(0)).unwrap()} } + #[inline] pub fn i32_(&self) -> i32 { // Safety: @@ -128,6 +135,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_I32_, Some(0)).unwrap()} } + #[inline] pub fn u32_(&self) -> u32 { // Safety: @@ -135,6 +143,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_U32_, Some(0)).unwrap()} } + #[inline] pub fn i64_(&self) -> i64 { // Safety: @@ -142,6 +151,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_I64_, Some(0)).unwrap()} } + #[inline] pub fn u64_(&self) -> u64 { // Safety: @@ -149,6 +159,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_U64_, Some(0)).unwrap()} } + #[inline] pub fn f32_(&self) -> f32 { // Safety: @@ -156,6 +167,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_F32_, Some(0.0)).unwrap()} } + #[inline] pub fn f64_(&self) -> f64 { // Safety: @@ -163,6 +175,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_F64_, Some(0.0)).unwrap()} } + #[inline] pub fn v8(&self) -> Option<::flatbuffers::Vector<'a, i8>> { // Safety: @@ -170,6 +183,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, i8>>>(TypeAliases::VT_V8, None)} } + #[inline] pub fn vf64(&self) -> Option<::flatbuffers::Vector<'a, f64>> { // Safety: @@ -201,6 +215,7 @@ impl ::flatbuffers::Verifiable for TypeAliases<'_> { Ok(()) } } + pub struct TypeAliasesArgs<'a> { pub i8_: i8, pub u8_: u8, @@ -215,6 +230,7 @@ pub struct TypeAliasesArgs<'a> { pub v8: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, i8>>>, pub vf64: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, f64>>>, } + impl<'a> Default for TypeAliasesArgs<'a> { #[inline] fn default() -> Self { @@ -239,55 +255,68 @@ pub struct TypeAliasesBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TypeAliasesBuilder<'a, 'b, A> { #[inline] pub fn add_i8_(&mut self, i8_: i8) { self.fbb_.push_slot::(TypeAliases::VT_I8_, i8_, 0); } + #[inline] pub fn add_u8_(&mut self, u8_: u8) { self.fbb_.push_slot::(TypeAliases::VT_U8_, u8_, 0); } + #[inline] pub fn add_i16_(&mut self, i16_: i16) { self.fbb_.push_slot::(TypeAliases::VT_I16_, i16_, 0); } + #[inline] pub fn add_u16_(&mut self, u16_: u16) { self.fbb_.push_slot::(TypeAliases::VT_U16_, u16_, 0); } + #[inline] pub fn add_i32_(&mut self, i32_: i32) { self.fbb_.push_slot::(TypeAliases::VT_I32_, i32_, 0); } + #[inline] pub fn add_u32_(&mut self, u32_: u32) { self.fbb_.push_slot::(TypeAliases::VT_U32_, u32_, 0); } + #[inline] pub fn add_i64_(&mut self, i64_: i64) { self.fbb_.push_slot::(TypeAliases::VT_I64_, i64_, 0); } + #[inline] pub fn add_u64_(&mut self, u64_: u64) { self.fbb_.push_slot::(TypeAliases::VT_U64_, u64_, 0); } + #[inline] pub fn add_f32_(&mut self, f32_: f32) { self.fbb_.push_slot::(TypeAliases::VT_F32_, f32_, 0.0); } + #[inline] pub fn add_f64_(&mut self, f64_: f64) { self.fbb_.push_slot::(TypeAliases::VT_F64_, f64_, 0.0); } + #[inline] pub fn add_v8(&mut self, v8: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , i8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(TypeAliases::VT_V8, v8); } + #[inline] pub fn add_vf64(&mut self, vf64: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , f64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(TypeAliases::VT_VF64, vf64); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TypeAliasesBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -296,6 +325,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TypeAliasesBuilder<'a, 'b, A> start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -321,6 +351,7 @@ impl ::core::fmt::Debug for TypeAliases<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TypeAliasesT { @@ -337,6 +368,7 @@ pub struct TypeAliasesT { pub v8: Option>, pub vf64: Option>, } + impl Default for TypeAliasesT { fn default() -> Self { Self { @@ -355,6 +387,7 @@ impl Default for TypeAliasesT { } } } + impl TypeAliasesT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &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..1a2c4cd23b9 100644 --- a/tests/monster_test/my_game/example/vec_3_generated.rs +++ b/tests/monster_test/my_game/example/vec_3_generated.rs @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct Vec3, aligned to 8 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Vec3(pub [u8; 32]); + impl Default for Vec3 { fn default() -> Self { Self([0; 32]) } } + impl ::core::fmt::Debug for Vec3 { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Vec3") @@ -25,27 +28,34 @@ impl ::core::fmt::Debug for Vec3 { } impl ::flatbuffers::SimpleToVerifyInSlice for Vec3 {} + impl<'a> ::flatbuffers::Follow<'a> for Vec3 { type Inner = &'a Vec3; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Vec3>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Vec3 { type Inner = &'a Vec3; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Vec3 { type Output = Vec3; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(8) @@ -263,6 +273,7 @@ pub struct Vec3T { pub test2: Color, pub test3: TestT, } + impl Vec3T { pub fn pack(&self) -> Vec3 { Vec3::new( @@ -275,4 +286,3 @@ impl Vec3T { ) } } - 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..6e142f106fd 100644 --- a/tests/monster_test/my_game/example_2/monster_generated.rs +++ b/tests/monster_test/my_game/example_2/monster_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum MonsterOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct Monster<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Monster<'a> { type Inner = Monster<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -18,7 +20,6 @@ impl<'a> ::flatbuffers::Follow<'a> for Monster<'a> { } impl<'a> Monster<'a> { - pub const fn get_fully_qualified_name() -> &'static str { "MyGame.Example2.Monster" } @@ -27,6 +28,7 @@ impl<'a> Monster<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Monster { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -52,8 +54,10 @@ impl ::flatbuffers::Verifiable for Monster<'_> { Ok(()) } } + pub struct MonsterArgs { } + impl<'a> Default for MonsterArgs { #[inline] fn default() -> Self { @@ -66,6 +70,7 @@ pub struct MonsterBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> { #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> MonsterBuilder<'a, 'b, A> { @@ -75,6 +80,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -88,16 +94,19 @@ impl ::core::fmt::Debug for Monster<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MonsterT { } + impl Default for MonsterT { fn default() -> Self { Self { } } } + impl MonsterT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..9911d3d08a2 100644 --- a/tests/monster_test/my_game/in_parent_namespace_generated.rs +++ b/tests/monster_test/my_game/in_parent_namespace_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum InParentNamespaceOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct InParentNamespace<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for InParentNamespace<'a> { type Inner = InParentNamespace<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -18,7 +20,6 @@ impl<'a> ::flatbuffers::Follow<'a> for InParentNamespace<'a> { } impl<'a> InParentNamespace<'a> { - pub const fn get_fully_qualified_name() -> &'static str { "MyGame.InParentNamespace" } @@ -27,6 +28,7 @@ impl<'a> InParentNamespace<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { InParentNamespace { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -52,8 +54,10 @@ impl ::flatbuffers::Verifiable for InParentNamespace<'_> { Ok(()) } } + pub struct InParentNamespaceArgs { } + impl<'a> Default for InParentNamespaceArgs { #[inline] fn default() -> Self { @@ -66,6 +70,7 @@ pub struct InParentNamespaceBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> InParentNamespaceBuilder<'a, 'b, A> { #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> InParentNamespaceBuilder<'a, 'b, A> { @@ -75,6 +80,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> InParentNamespaceBuilder<'a, start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -88,16 +94,19 @@ impl ::core::fmt::Debug for InParentNamespace<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct InParentNamespaceT { } + impl Default for InParentNamespaceT { fn default() -> Self { Self { } } } + impl InParentNamespaceT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..4e03e2decd3 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 @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_FROM_INCLUDE: i64 = 0; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ @@ -15,6 +18,7 @@ pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct FromInclude(pub i64); + #[allow(non_upper_case_globals)] impl FromInclude { pub const IncludeVal: Self = Self(0); @@ -24,6 +28,7 @@ impl FromInclude { pub const ENUM_VALUES: &'static [Self] = &[ Self::IncludeVal, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -32,6 +37,7 @@ impl FromInclude { } } } + impl ::core::fmt::Debug for FromInclude { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -41,8 +47,10 @@ impl ::core::fmt::Debug for FromInclude { } } } + impl<'a> ::flatbuffers::Follow<'a> for FromInclude { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -52,6 +60,7 @@ impl<'a> ::flatbuffers::Follow<'a> for FromInclude { impl ::flatbuffers::Push for FromInclude { type Output = FromInclude; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -60,10 +69,12 @@ impl ::flatbuffers::Push for FromInclude { impl ::flatbuffers::EndianScalar for FromInclude { type Scalar = i64; + #[inline] fn to_little_endian(self) -> i64 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i64) -> Self { 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..5e969c2dcd3 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TableBOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableB<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableB<'a> { type Inner = TableB<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> TableB<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableB { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -67,9 +70,11 @@ impl ::flatbuffers::Verifiable for TableB<'_> { Ok(()) } } + pub struct TableBArgs<'a> { pub a: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableBArgs<'a> { #[inline] fn default() -> Self { @@ -83,11 +88,13 @@ pub struct TableBBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { #[inline] pub fn add_a(&mut self, a: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableB::VT_A, a); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableBBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -96,6 +103,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -110,11 +118,13 @@ impl ::core::fmt::Debug for TableB<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableBT { pub a: Option>, } + impl Default for TableBT { fn default() -> Self { Self { @@ -122,6 +132,7 @@ impl Default for TableBT { } } } + impl TableBT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &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..e8639acf2b6 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 @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct Unused, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Unused(pub [u8; 4]); + impl Default for Unused { fn default() -> Self { Self([0; 4]) } } + impl ::core::fmt::Debug for Unused { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Unused") @@ -20,27 +23,34 @@ impl ::core::fmt::Debug for Unused { } impl ::flatbuffers::SimpleToVerifyInSlice for Unused {} + impl<'a> ::flatbuffers::Follow<'a> for Unused { type Inner = &'a Unused; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Unused>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Unused { type Inner = &'a Unused; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Unused { type Output = Unused; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -110,6 +120,7 @@ impl<'a> Unused { pub struct UnusedT { pub a: i32, } + impl UnusedT { pub fn pack(&self) -> Unused { Unused::new( @@ -117,4 +128,3 @@ impl UnusedT { ) } } - diff --git a/tests/monster_test/table_a_generated.rs b/tests/monster_test/table_a_generated.rs index ca29250dc3a..2558b840659 100644 --- a/tests/monster_test/table_a_generated.rs +++ b/tests/monster_test/table_a_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TableAOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableA<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableA<'a> { type Inner = TableA<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> TableA<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableA { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -67,9 +70,11 @@ impl ::flatbuffers::Verifiable for TableA<'_> { Ok(()) } } + pub struct TableAArgs<'a> { pub b: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableAArgs<'a> { #[inline] fn default() -> Self { @@ -83,11 +88,13 @@ pub struct TableABuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { #[inline] pub fn add_b(&mut self, b: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableA::VT_B, b); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableABuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -96,6 +103,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -110,11 +118,13 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableAT { pub b: Option>, } + impl Default for TableAT { fn default() -> Self { Self { @@ -122,6 +132,7 @@ impl Default for TableAT { } } } + impl TableAT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &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..1e1aebc8f0f 100644 --- a/tests/monster_test_serialize/my_game/example/ability_generated.rs +++ b/tests/monster_test_serialize/my_game/example/ability_generated.rs @@ -4,15 +4,18 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + // struct Ability, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Ability(pub [u8; 8]); + impl Default for Ability { fn default() -> Self { Self([0; 8]) } } + impl ::core::fmt::Debug for Ability { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Ability") @@ -23,27 +26,34 @@ impl ::core::fmt::Debug for Ability { } impl ::flatbuffers::SimpleToVerifyInSlice for Ability {} + impl<'a> ::flatbuffers::Follow<'a> for Ability { type Inner = &'a Ability; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Ability>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Ability { type Inner = &'a Ability; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Ability { type Output = Ability; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Ability as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -116,6 +126,7 @@ impl<'a> Ability { } } + #[inline] pub fn key_compare_less_than(&self, o: &Ability) -> bool { self.id() < o.id() @@ -168,6 +179,7 @@ pub struct AbilityT { pub id: u32, pub distance: u32, } + impl AbilityT { pub fn pack(&self) -> Ability { Ability::new( @@ -176,4 +188,3 @@ impl AbilityT { ) } } - 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..ec6c62cc075 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 @@ -4,10 +4,13 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ANY_AMBIGUOUS_ALIASES: u8 = 3; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ANY_AMBIGUOUS_ALIASES: [AnyAmbiguousAliases; 4] = [ @@ -20,6 +23,7 @@ pub const ENUM_VALUES_ANY_AMBIGUOUS_ALIASES: [AnyAmbiguousAliases; 4] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct AnyAmbiguousAliases(pub u8); + #[allow(non_upper_case_globals)] impl AnyAmbiguousAliases { pub const NONE: Self = Self(0); @@ -35,6 +39,7 @@ impl AnyAmbiguousAliases { Self::M2, Self::M3, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -46,6 +51,7 @@ impl AnyAmbiguousAliases { } } } + impl ::core::fmt::Debug for AnyAmbiguousAliases { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -55,6 +61,7 @@ impl ::core::fmt::Debug for AnyAmbiguousAliases { } } } + impl Serialize for AnyAmbiguousAliases { fn serialize(&self, serializer: S) -> Result where @@ -85,6 +92,7 @@ impl<'de> serde::Deserialize<'de> for AnyAmbiguousAliases { impl<'a> ::flatbuffers::Follow<'a> for AnyAmbiguousAliases { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -94,6 +102,7 @@ impl<'a> ::flatbuffers::Follow<'a> for AnyAmbiguousAliases { impl ::flatbuffers::Push for AnyAmbiguousAliases { type Output = AnyAmbiguousAliases; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -102,10 +111,12 @@ impl ::flatbuffers::Push for AnyAmbiguousAliases { impl ::flatbuffers::EndianScalar for AnyAmbiguousAliases { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -124,6 +135,7 @@ impl<'a> ::flatbuffers::Verifiable for AnyAmbiguousAliases { } impl ::flatbuffers::SimpleToVerifyInSlice for AnyAmbiguousAliases {} + pub struct AnyAmbiguousAliasesUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -135,11 +147,13 @@ pub enum AnyAmbiguousAliasesT { M2(alloc::boxed::Box), M3(alloc::boxed::Box), } + impl Default for AnyAmbiguousAliasesT { fn default() -> Self { Self::NONE } } + impl AnyAmbiguousAliasesT { pub fn any_ambiguous_aliases_type(&self) -> AnyAmbiguousAliases { match self { @@ -149,6 +163,7 @@ impl AnyAmbiguousAliasesT { Self::M3(_) => AnyAmbiguousAliases::M3, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, @@ -157,6 +172,7 @@ impl AnyAmbiguousAliasesT { Self::M3(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m1(&mut self) -> Option> { if let Self::M1(_) = self { @@ -170,14 +186,17 @@ impl AnyAmbiguousAliasesT { None } } + /// If the union variant matches, return a reference to the MonsterT. pub fn as_m1(&self) -> Option<&MonsterT> { if let Self::M1(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the MonsterT. pub fn as_m1_mut(&mut self) -> Option<&mut MonsterT> { 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> { if let Self::M2(_) = self { @@ -191,14 +210,17 @@ impl AnyAmbiguousAliasesT { None } } + /// If the union variant matches, return a reference to the MonsterT. pub fn as_m2(&self) -> Option<&MonsterT> { if let Self::M2(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the MonsterT. pub fn as_m2_mut(&mut self) -> Option<&mut MonsterT> { 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> { if let Self::M3(_) = self { @@ -212,12 +234,15 @@ impl AnyAmbiguousAliasesT { None } } + /// If the union variant matches, return a reference to the MonsterT. pub fn as_m3(&self) -> Option<&MonsterT> { if let Self::M3(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the MonsterT. pub fn as_m3_mut(&mut self) -> Option<&mut MonsterT> { if let Self::M3(v) = self { Some(v.as_mut()) } else { None } } } + 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..0f5be1a874c 100644 --- a/tests/monster_test_serialize/my_game/example/any_generated.rs +++ b/tests/monster_test_serialize/my_game/example/any_generated.rs @@ -4,10 +4,13 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ANY: u8 = 3; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ANY: [Any; 4] = [ @@ -20,6 +23,7 @@ pub const ENUM_VALUES_ANY: [Any; 4] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Any(pub u8); + #[allow(non_upper_case_globals)] impl Any { pub const NONE: Self = Self(0); @@ -35,6 +39,7 @@ impl Any { Self::TestSimpleTableWithEnum, Self::MyGame_Example2_Monster, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -46,6 +51,7 @@ impl Any { } } } + impl ::core::fmt::Debug for Any { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -55,6 +61,7 @@ impl ::core::fmt::Debug for Any { } } } + impl Serialize for Any { fn serialize(&self, serializer: S) -> Result where @@ -85,6 +92,7 @@ impl<'de> serde::Deserialize<'de> for Any { impl<'a> ::flatbuffers::Follow<'a> for Any { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -94,6 +102,7 @@ impl<'a> ::flatbuffers::Follow<'a> for Any { impl ::flatbuffers::Push for Any { type Output = Any; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -102,10 +111,12 @@ impl ::flatbuffers::Push for Any { impl ::flatbuffers::EndianScalar for Any { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -124,6 +135,7 @@ impl<'a> ::flatbuffers::Verifiable for Any { } impl ::flatbuffers::SimpleToVerifyInSlice for Any {} + pub struct AnyUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -135,11 +147,13 @@ pub enum AnyT { TestSimpleTableWithEnum(alloc::boxed::Box), MyGameExample2Monster(alloc::boxed::Box), } + impl Default for AnyT { fn default() -> Self { Self::NONE } } + impl AnyT { pub fn any_type(&self) -> Any { match self { @@ -149,6 +163,7 @@ impl AnyT { Self::MyGameExample2Monster(_) => Any::MyGame_Example2_Monster, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, @@ -157,6 +172,7 @@ impl AnyT { Self::MyGameExample2Monster(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_monster(&mut self) -> Option> { if let Self::Monster(_) = self { @@ -170,14 +186,17 @@ impl AnyT { None } } + /// If the union variant matches, return a reference to the MonsterT. pub fn as_monster(&self) -> Option<&MonsterT> { if let Self::Monster(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the MonsterT. pub fn as_monster_mut(&mut self) -> Option<&mut MonsterT> { 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> { if let Self::TestSimpleTableWithEnum(_) = self { @@ -191,14 +210,17 @@ impl AnyT { None } } + /// If the union variant matches, return a reference to the TestSimpleTableWithEnumT. pub fn as_test_simple_table_with_enum(&self) -> Option<&TestSimpleTableWithEnumT> { if let Self::TestSimpleTableWithEnum(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the TestSimpleTableWithEnumT. pub fn as_test_simple_table_with_enum_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT> { 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> { if let Self::MyGameExample2Monster(_) = self { @@ -212,12 +234,15 @@ impl AnyT { None } } + /// If the union variant matches, return a reference to the super::example_2::MonsterT. pub fn as_my_game_example_2_monster(&self) -> Option<&super::example_2::MonsterT> { if let Self::MyGameExample2Monster(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the super::example_2::MonsterT. pub fn as_my_game_example_2_monster_mut(&mut self) -> Option<&mut super::example_2::MonsterT> { if let Self::MyGameExample2Monster(v) = self { Some(v.as_mut()) } else { None } } } + 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..067f2f62053 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 @@ -4,10 +4,13 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ANY_UNIQUE_ALIASES: u8 = 3; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ANY_UNIQUE_ALIASES: [AnyUniqueAliases; 4] = [ @@ -20,6 +23,7 @@ pub const ENUM_VALUES_ANY_UNIQUE_ALIASES: [AnyUniqueAliases; 4] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct AnyUniqueAliases(pub u8); + #[allow(non_upper_case_globals)] impl AnyUniqueAliases { pub const NONE: Self = Self(0); @@ -35,6 +39,7 @@ impl AnyUniqueAliases { Self::TS, Self::M2, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -46,6 +51,7 @@ impl AnyUniqueAliases { } } } + impl ::core::fmt::Debug for AnyUniqueAliases { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -55,6 +61,7 @@ impl ::core::fmt::Debug for AnyUniqueAliases { } } } + impl Serialize for AnyUniqueAliases { fn serialize(&self, serializer: S) -> Result where @@ -85,6 +92,7 @@ impl<'de> serde::Deserialize<'de> for AnyUniqueAliases { impl<'a> ::flatbuffers::Follow<'a> for AnyUniqueAliases { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -94,6 +102,7 @@ impl<'a> ::flatbuffers::Follow<'a> for AnyUniqueAliases { impl ::flatbuffers::Push for AnyUniqueAliases { type Output = AnyUniqueAliases; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -102,10 +111,12 @@ impl ::flatbuffers::Push for AnyUniqueAliases { impl ::flatbuffers::EndianScalar for AnyUniqueAliases { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -124,6 +135,7 @@ impl<'a> ::flatbuffers::Verifiable for AnyUniqueAliases { } impl ::flatbuffers::SimpleToVerifyInSlice for AnyUniqueAliases {} + pub struct AnyUniqueAliasesUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -135,11 +147,13 @@ pub enum AnyUniqueAliasesT { TS(alloc::boxed::Box), M2(alloc::boxed::Box), } + impl Default for AnyUniqueAliasesT { fn default() -> Self { Self::NONE } } + impl AnyUniqueAliasesT { pub fn any_unique_aliases_type(&self) -> AnyUniqueAliases { match self { @@ -149,6 +163,7 @@ impl AnyUniqueAliasesT { Self::M2(_) => AnyUniqueAliases::M2, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, @@ -157,6 +172,7 @@ impl AnyUniqueAliasesT { Self::M2(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m(&mut self) -> Option> { if let Self::M(_) = self { @@ -170,14 +186,17 @@ impl AnyUniqueAliasesT { None } } + /// If the union variant matches, return a reference to the MonsterT. pub fn as_m(&self) -> Option<&MonsterT> { if let Self::M(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the MonsterT. pub fn as_m_mut(&mut self) -> Option<&mut MonsterT> { 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> { if let Self::TS(_) = self { @@ -191,14 +210,17 @@ impl AnyUniqueAliasesT { None } } + /// If the union variant matches, return a reference to the TestSimpleTableWithEnumT. pub fn as_ts(&self) -> Option<&TestSimpleTableWithEnumT> { if let Self::TS(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the TestSimpleTableWithEnumT. pub fn as_ts_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT> { 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> { if let Self::M2(_) = self { @@ -212,12 +234,15 @@ impl AnyUniqueAliasesT { None } } + /// If the union variant matches, return a reference to the super::example_2::MonsterT. pub fn as_m2(&self) -> Option<&super::example_2::MonsterT> { if let Self::M2(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the super::example_2::MonsterT. pub fn as_m2_mut(&mut self) -> Option<&mut super::example_2::MonsterT> { if let Self::M2(v) = self { Some(v.as_mut()) } else { None } } } + 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..bfcfd83543a 100644 --- a/tests/monster_test_serialize/my_game/example/color_generated.rs +++ b/tests/monster_test_serialize/my_game/example/color_generated.rs @@ -4,6 +4,7 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + #[allow(non_upper_case_globals)] mod bitflags_color { ::flatbuffers::bitflags::bitflags! { @@ -19,6 +20,7 @@ mod bitflags_color { } } } + pub use self::bitflags_color::Color; impl Serialize for Color { @@ -32,6 +34,7 @@ impl Serialize for Color { impl<'a> ::flatbuffers::Follow<'a> for Color { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -41,6 +44,7 @@ impl<'a> ::flatbuffers::Follow<'a> for Color { impl ::flatbuffers::Push for Color { type Output = Color; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.bits()) }; @@ -49,10 +53,12 @@ impl ::flatbuffers::Push for Color { impl ::flatbuffers::EndianScalar for Color { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.bits().to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { 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..0d007163782 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 @@ -4,6 +4,7 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + #[allow(non_upper_case_globals)] mod bitflags_long_enum { ::flatbuffers::bitflags::bitflags! { @@ -15,6 +16,7 @@ mod bitflags_long_enum { } } } + pub use self::bitflags_long_enum::LongEnum; impl Serialize for LongEnum { @@ -28,6 +30,7 @@ impl Serialize for LongEnum { impl<'a> ::flatbuffers::Follow<'a> for LongEnum { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -37,6 +40,7 @@ impl<'a> ::flatbuffers::Follow<'a> for LongEnum { impl ::flatbuffers::Push for LongEnum { type Output = LongEnum; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.bits()) }; @@ -45,10 +49,12 @@ impl ::flatbuffers::Push for LongEnum { impl ::flatbuffers::EndianScalar for LongEnum { type Scalar = u64; + #[inline] fn to_little_endian(self) -> u64 { self.bits().to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u64) -> Self { 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..1f8128c1c6c 100644 --- a/tests/monster_test_serialize/my_game/example/monster_generated.rs +++ b/tests/monster_test_serialize/my_game/example/monster_generated.rs @@ -4,16 +4,18 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + pub enum MonsterOffset {} -#[derive(Copy, Clone, PartialEq)] /// an example documentation comment: "monster object" +#[derive(Copy, Clone, PartialEq)] pub struct Monster<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Monster<'a> { type Inner = Monster<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -91,6 +93,7 @@ impl<'a> Monster<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Monster { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -396,6 +399,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_POS, None)} } + #[inline] pub fn mana(&self) -> i16 { // Safety: @@ -403,6 +407,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_MANA, Some(150)).unwrap()} } + #[inline] pub fn hp(&self) -> i16 { // Safety: @@ -410,6 +415,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_HP, Some(100)).unwrap()} } + #[inline] pub fn name(&self) -> &'a str { // Safety: @@ -417,6 +423,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()} } + #[inline] pub fn key_compare_less_than(&self, o: &Monster) -> bool { self.name() < o.name() @@ -427,6 +434,7 @@ impl<'a> Monster<'a> { let key = self.name(); key.cmp(val) } + #[inline] pub fn inventory(&self) -> Option<::flatbuffers::Vector<'a, u8>> { // Safety: @@ -434,6 +442,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None)} } + #[inline] pub fn color(&self) -> Color { // Safety: @@ -441,6 +450,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_COLOR, Some(Color::Blue)).unwrap()} } + #[inline] pub fn test_type(&self) -> Any { // Safety: @@ -448,6 +458,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TEST_TYPE, Some(Any::NONE)).unwrap()} } + #[inline] pub fn test(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -455,6 +466,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(Monster::VT_TEST, None)} } + #[inline] pub fn test4(&self) -> Option<::flatbuffers::Vector<'a, Test>> { // Safety: @@ -462,6 +474,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST4, None)} } + #[inline] pub fn testarrayofstring(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<&'a str>>> { // Safety: @@ -469,6 +482,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING, None)} } + /// an example documentation comment: this will end up in the generated code /// multiline too #[inline] @@ -478,6 +492,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Monster::VT_TESTARRAYOFTABLES, None)} } + #[inline] pub fn enemy(&self) -> Option> { // Safety: @@ -485,6 +500,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(Monster::VT_ENEMY, None)} } + #[inline] pub fn testnestedflatbuffer(&self) -> Option<::flatbuffers::Vector<'a, u8>> { // Safety: @@ -492,6 +508,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTNESTEDFLATBUFFER, None)} } + pub fn testnestedflatbuffer_nested_flatbuffer(&'a self) -> Option> { self.testnestedflatbuffer().map(|data| { use ::flatbuffers::Follow; @@ -501,6 +518,7 @@ impl<'a> Monster<'a> { unsafe { <::flatbuffers::ForwardsUOffset>>::follow(data.bytes(), 0) } }) } + #[inline] pub fn testempty(&self) -> Option> { // Safety: @@ -508,6 +526,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(Monster::VT_TESTEMPTY, None)} } + #[inline] pub fn testbool(&self) -> bool { // Safety: @@ -515,6 +534,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTBOOL, Some(false)).unwrap()} } + #[inline] pub fn testhashs32_fnv1(&self) -> i32 { // Safety: @@ -522,6 +542,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHS32_FNV1, Some(0)).unwrap()} } + #[inline] pub fn testhashu32_fnv1(&self) -> u32 { // Safety: @@ -529,6 +550,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHU32_FNV1, Some(0)).unwrap()} } + #[inline] pub fn testhashs64_fnv1(&self) -> i64 { // Safety: @@ -536,6 +558,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHS64_FNV1, Some(0)).unwrap()} } + #[inline] pub fn testhashu64_fnv1(&self) -> u64 { // Safety: @@ -543,6 +566,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHU64_FNV1, Some(0)).unwrap()} } + #[inline] pub fn testhashs32_fnv1a(&self) -> i32 { // Safety: @@ -550,6 +574,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHS32_FNV1A, Some(0)).unwrap()} } + #[inline] pub fn testhashu32_fnv1a(&self) -> u32 { // Safety: @@ -557,6 +582,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHU32_FNV1A, Some(0)).unwrap()} } + #[inline] pub fn testhashs64_fnv1a(&self) -> i64 { // Safety: @@ -564,6 +590,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHS64_FNV1A, Some(0)).unwrap()} } + #[inline] pub fn testhashu64_fnv1a(&self) -> u64 { // Safety: @@ -571,6 +598,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTHASHU64_FNV1A, Some(0)).unwrap()} } + #[inline] pub fn testarrayofbools(&self) -> Option<::flatbuffers::Vector<'a, bool>> { // Safety: @@ -578,6 +606,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, bool>>>(Monster::VT_TESTARRAYOFBOOLS, None)} } + #[inline] pub fn testf(&self) -> f32 { // Safety: @@ -585,6 +614,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTF, Some(3.14159)).unwrap()} } + #[inline] pub fn testf2(&self) -> f32 { // Safety: @@ -592,6 +622,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTF2, Some(3.0)).unwrap()} } + #[inline] pub fn testf3(&self) -> f32 { // Safety: @@ -599,6 +630,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_TESTF3, Some(0.0)).unwrap()} } + #[inline] pub fn testarrayofstring2(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<&'a str>>> { // Safety: @@ -606,6 +638,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING2, None)} } + #[inline] pub fn testarrayofsortedstruct(&self) -> Option<::flatbuffers::Vector<'a, Ability>> { // Safety: @@ -613,6 +646,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, Ability>>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, None)} } + #[inline] pub fn flex(&self) -> Option<::flatbuffers::Vector<'a, u8>> { // Safety: @@ -620,6 +654,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u8>>>(Monster::VT_FLEX, None)} } + #[inline] pub fn test5(&self) -> Option<::flatbuffers::Vector<'a, Test>> { // Safety: @@ -627,6 +662,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST5, None)} } + #[inline] pub fn vector_of_longs(&self) -> Option<::flatbuffers::Vector<'a, i64>> { // Safety: @@ -634,6 +670,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, i64>>>(Monster::VT_VECTOR_OF_LONGS, None)} } + #[inline] pub fn vector_of_doubles(&self) -> Option<::flatbuffers::Vector<'a, f64>> { // Safety: @@ -641,6 +678,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, f64>>>(Monster::VT_VECTOR_OF_DOUBLES, None)} } + #[inline] pub fn parent_namespace_test(&self) -> Option> { // Safety: @@ -648,6 +686,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(Monster::VT_PARENT_NAMESPACE_TEST, None)} } + #[inline] pub fn vector_of_referrables(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>> { // Safety: @@ -655,6 +694,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Monster::VT_VECTOR_OF_REFERRABLES, None)} } + #[inline] pub fn single_weak_reference(&self) -> u64 { // Safety: @@ -662,6 +702,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_SINGLE_WEAK_REFERENCE, Some(0)).unwrap()} } + #[inline] pub fn vector_of_weak_references(&self) -> Option<::flatbuffers::Vector<'a, u64>> { // Safety: @@ -669,6 +710,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, None)} } + #[inline] pub fn vector_of_strong_referrables(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>> { // Safety: @@ -676,6 +718,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, None)} } + #[inline] pub fn co_owning_reference(&self) -> u64 { // Safety: @@ -683,6 +726,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_CO_OWNING_REFERENCE, Some(0)).unwrap()} } + #[inline] pub fn vector_of_co_owning_references(&self) -> Option<::flatbuffers::Vector<'a, u64>> { // Safety: @@ -690,6 +734,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, None)} } + #[inline] pub fn non_owning_reference(&self) -> u64 { // Safety: @@ -697,6 +742,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_NON_OWNING_REFERENCE, Some(0)).unwrap()} } + #[inline] pub fn vector_of_non_owning_references(&self) -> Option<::flatbuffers::Vector<'a, u64>> { // Safety: @@ -704,6 +750,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, None)} } + #[inline] pub fn any_unique_type(&self) -> AnyUniqueAliases { // Safety: @@ -711,6 +758,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_ANY_UNIQUE_TYPE, Some(AnyUniqueAliases::NONE)).unwrap()} } + #[inline] pub fn any_unique(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -718,6 +766,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(Monster::VT_ANY_UNIQUE, None)} } + #[inline] pub fn any_ambiguous_type(&self) -> AnyAmbiguousAliases { // Safety: @@ -725,6 +774,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_ANY_AMBIGUOUS_TYPE, Some(AnyAmbiguousAliases::NONE)).unwrap()} } + #[inline] pub fn any_ambiguous(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -732,6 +782,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(Monster::VT_ANY_AMBIGUOUS, None)} } + #[inline] pub fn vector_of_enums(&self) -> Option<::flatbuffers::Vector<'a, Color>> { // Safety: @@ -739,6 +790,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)} } + #[inline] pub fn signed_enum(&self) -> Race { // Safety: @@ -746,6 +798,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()} } + #[inline] pub fn testrequirednestedflatbuffer(&self) -> Option<::flatbuffers::Vector<'a, u8>> { // Safety: @@ -753,6 +806,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, None)} } + pub fn testrequirednestedflatbuffer_nested_flatbuffer(&'a self) -> Option> { self.testrequirednestedflatbuffer().map(|data| { use ::flatbuffers::Follow; @@ -762,6 +816,7 @@ impl<'a> Monster<'a> { unsafe { <::flatbuffers::ForwardsUOffset>>::follow(data.bytes(), 0) } }) } + #[inline] pub fn scalar_key_sorted_tables(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>> { // Safety: @@ -769,6 +824,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset>>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, None)} } + #[inline] pub fn native_inline(&self) -> Option<&'a Test> { // Safety: @@ -776,6 +832,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_NATIVE_INLINE, None)} } + #[inline] pub fn long_enum_non_enum_default(&self) -> LongEnum { // Safety: @@ -783,6 +840,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, Some(Default::default())).unwrap()} } + #[inline] pub fn long_enum_normal_default(&self) -> LongEnum { // Safety: @@ -790,6 +848,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, Some(LongEnum::LongOne)).unwrap()} } + #[inline] pub fn nan_default(&self) -> f32 { // Safety: @@ -797,6 +856,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_NAN_DEFAULT, Some(f32::NAN)).unwrap()} } + #[inline] pub fn inf_default(&self) -> f32 { // Safety: @@ -804,6 +864,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_INF_DEFAULT, Some(f32::INFINITY)).unwrap()} } + #[inline] pub fn positive_inf_default(&self) -> f32 { // Safety: @@ -811,6 +872,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_POSITIVE_INF_DEFAULT, Some(f32::INFINITY)).unwrap()} } + #[inline] pub fn infinity_default(&self) -> f32 { // Safety: @@ -818,6 +880,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_INFINITY_DEFAULT, Some(f32::INFINITY)).unwrap()} } + #[inline] pub fn positive_infinity_default(&self) -> f32 { // Safety: @@ -825,6 +888,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_POSITIVE_INFINITY_DEFAULT, Some(f32::INFINITY)).unwrap()} } + #[inline] pub fn negative_inf_default(&self) -> f32 { // Safety: @@ -832,6 +896,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_NEGATIVE_INF_DEFAULT, Some(f32::NEG_INFINITY)).unwrap()} } + #[inline] pub fn negative_infinity_default(&self) -> f32 { // Safety: @@ -839,6 +904,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_NEGATIVE_INFINITY_DEFAULT, Some(f32::NEG_INFINITY)).unwrap()} } + #[inline] pub fn double_inf_default(&self) -> f64 { // Safety: @@ -846,6 +912,7 @@ impl<'a> Monster<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Monster::VT_DOUBLE_INF_DEFAULT, Some(f64::INFINITY)).unwrap()} } + #[inline] #[allow(non_snake_case)] pub fn test_as_monster(&self) -> Option> { @@ -980,7 +1047,6 @@ impl<'a> Monster<'a> { None } } - } impl ::flatbuffers::Verifiable for Monster<'_> { @@ -1072,6 +1138,7 @@ impl ::flatbuffers::Verifiable for Monster<'_> { Ok(()) } } + pub struct MonsterArgs<'a> { pub pos: Option<&'a Vec3>, pub mana: i16, @@ -1135,6 +1202,7 @@ pub struct MonsterArgs<'a> { pub negative_infinity_default: f32, pub double_inf_default: f64, } + impl<'a> Default for MonsterArgs<'a> { #[inline] fn default() -> Self { @@ -1433,251 +1501,313 @@ pub struct MonsterBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> { #[inline] pub fn add_pos(&mut self, pos: &Vec3) { self.fbb_.push_slot_always::<&Vec3>(Monster::VT_POS, pos); } + #[inline] pub fn add_mana(&mut self, mana: i16) { self.fbb_.push_slot::(Monster::VT_MANA, mana, 150); } + #[inline] pub fn add_hp(&mut self, hp: i16) { self.fbb_.push_slot::(Monster::VT_HP, hp, 100); } + #[inline] pub fn add_name(&mut self, name: ::flatbuffers::WIPOffset<&'b str>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_NAME, name); } + #[inline] pub fn add_inventory(&mut self, inventory: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_INVENTORY, inventory); } + #[inline] pub fn add_color(&mut self, color: Color) { self.fbb_.push_slot::(Monster::VT_COLOR, color, Color::Blue); } + #[inline] pub fn add_test_type(&mut self, test_type: Any) { self.fbb_.push_slot::(Monster::VT_TEST_TYPE, test_type, Any::NONE); } + #[inline] pub fn add_test(&mut self, test: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TEST, test); } + #[inline] pub fn add_test4(&mut self, test4: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , Test>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TEST4, test4); } + #[inline] pub fn add_testarrayofstring(&mut self, testarrayofstring: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset<&'b str>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTARRAYOFSTRING, testarrayofstring); } + #[inline] pub fn add_testarrayoftables(&mut self, testarrayoftables: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTARRAYOFTABLES, testarrayoftables); } + #[inline] pub fn add_enemy(&mut self, enemy: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(Monster::VT_ENEMY, enemy); } + #[inline] pub fn add_testnestedflatbuffer(&mut self, testnestedflatbuffer: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTNESTEDFLATBUFFER, testnestedflatbuffer); } + #[inline] pub fn add_testempty(&mut self, testempty: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(Monster::VT_TESTEMPTY, testempty); } + #[inline] pub fn add_testbool(&mut self, testbool: bool) { self.fbb_.push_slot::(Monster::VT_TESTBOOL, testbool, false); } + #[inline] pub fn add_testhashs32_fnv1(&mut self, testhashs32_fnv1: i32) { self.fbb_.push_slot::(Monster::VT_TESTHASHS32_FNV1, testhashs32_fnv1, 0); } + #[inline] pub fn add_testhashu32_fnv1(&mut self, testhashu32_fnv1: u32) { self.fbb_.push_slot::(Monster::VT_TESTHASHU32_FNV1, testhashu32_fnv1, 0); } + #[inline] pub fn add_testhashs64_fnv1(&mut self, testhashs64_fnv1: i64) { self.fbb_.push_slot::(Monster::VT_TESTHASHS64_FNV1, testhashs64_fnv1, 0); } + #[inline] pub fn add_testhashu64_fnv1(&mut self, testhashu64_fnv1: u64) { self.fbb_.push_slot::(Monster::VT_TESTHASHU64_FNV1, testhashu64_fnv1, 0); } + #[inline] pub fn add_testhashs32_fnv1a(&mut self, testhashs32_fnv1a: i32) { self.fbb_.push_slot::(Monster::VT_TESTHASHS32_FNV1A, testhashs32_fnv1a, 0); } + #[inline] pub fn add_testhashu32_fnv1a(&mut self, testhashu32_fnv1a: u32) { self.fbb_.push_slot::(Monster::VT_TESTHASHU32_FNV1A, testhashu32_fnv1a, 0); } + #[inline] pub fn add_testhashs64_fnv1a(&mut self, testhashs64_fnv1a: i64) { self.fbb_.push_slot::(Monster::VT_TESTHASHS64_FNV1A, testhashs64_fnv1a, 0); } + #[inline] pub fn add_testhashu64_fnv1a(&mut self, testhashu64_fnv1a: u64) { self.fbb_.push_slot::(Monster::VT_TESTHASHU64_FNV1A, testhashu64_fnv1a, 0); } + #[inline] pub fn add_testarrayofbools(&mut self, testarrayofbools: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , bool>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTARRAYOFBOOLS, testarrayofbools); } + #[inline] pub fn add_testf(&mut self, testf: f32) { self.fbb_.push_slot::(Monster::VT_TESTF, testf, 3.14159); } + #[inline] pub fn add_testf2(&mut self, testf2: f32) { self.fbb_.push_slot::(Monster::VT_TESTF2, testf2, 3.0); } + #[inline] pub fn add_testf3(&mut self, testf3: f32) { self.fbb_.push_slot::(Monster::VT_TESTF3, testf3, 0.0); } + #[inline] pub fn add_testarrayofstring2(&mut self, testarrayofstring2: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset<&'b str>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTARRAYOFSTRING2, testarrayofstring2); } + #[inline] pub fn add_testarrayofsortedstruct(&mut self, testarrayofsortedstruct: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , Ability>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, testarrayofsortedstruct); } + #[inline] pub fn add_flex(&mut self, flex: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_FLEX, flex); } + #[inline] pub fn add_test5(&mut self, test5: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , Test>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TEST5, test5); } + #[inline] pub fn add_vector_of_longs(&mut self, vector_of_longs: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , i64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_LONGS, vector_of_longs); } + #[inline] pub fn add_vector_of_doubles(&mut self, vector_of_doubles: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , f64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_DOUBLES, vector_of_doubles); } + #[inline] pub fn add_parent_namespace_test(&mut self, parent_namespace_test: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(Monster::VT_PARENT_NAMESPACE_TEST, parent_namespace_test); } + #[inline] pub fn add_vector_of_referrables(&mut self, vector_of_referrables: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_REFERRABLES, vector_of_referrables); } + #[inline] pub fn add_single_weak_reference(&mut self, single_weak_reference: u64) { self.fbb_.push_slot::(Monster::VT_SINGLE_WEAK_REFERENCE, single_weak_reference, 0); } + #[inline] pub fn add_vector_of_weak_references(&mut self, vector_of_weak_references: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, vector_of_weak_references); } + #[inline] pub fn add_vector_of_strong_referrables(&mut self, vector_of_strong_referrables: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, vector_of_strong_referrables); } + #[inline] pub fn add_co_owning_reference(&mut self, co_owning_reference: u64) { self.fbb_.push_slot::(Monster::VT_CO_OWNING_REFERENCE, co_owning_reference, 0); } + #[inline] pub fn add_vector_of_co_owning_references(&mut self, vector_of_co_owning_references: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, vector_of_co_owning_references); } + #[inline] pub fn add_non_owning_reference(&mut self, non_owning_reference: u64) { self.fbb_.push_slot::(Monster::VT_NON_OWNING_REFERENCE, non_owning_reference, 0); } + #[inline] pub fn add_vector_of_non_owning_references(&mut self, vector_of_non_owning_references: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, vector_of_non_owning_references); } + #[inline] pub fn add_any_unique_type(&mut self, any_unique_type: AnyUniqueAliases) { self.fbb_.push_slot::(Monster::VT_ANY_UNIQUE_TYPE, any_unique_type, AnyUniqueAliases::NONE); } + #[inline] pub fn add_any_unique(&mut self, any_unique: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_ANY_UNIQUE, any_unique); } + #[inline] pub fn add_any_ambiguous_type(&mut self, any_ambiguous_type: AnyAmbiguousAliases) { self.fbb_.push_slot::(Monster::VT_ANY_AMBIGUOUS_TYPE, any_ambiguous_type, AnyAmbiguousAliases::NONE); } + #[inline] pub fn add_any_ambiguous(&mut self, any_ambiguous: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_ANY_AMBIGUOUS, any_ambiguous); } + #[inline] pub fn add_vector_of_enums(&mut self, vector_of_enums: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , Color>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_ENUMS, vector_of_enums); } + #[inline] pub fn add_signed_enum(&mut self, signed_enum: Race) { self.fbb_.push_slot::(Monster::VT_SIGNED_ENUM, signed_enum, Race::None); } + #[inline] pub fn add_testrequirednestedflatbuffer(&mut self, testrequirednestedflatbuffer: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , u8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, testrequirednestedflatbuffer); } + #[inline] pub fn add_scalar_key_sorted_tables(&mut self, scalar_key_sorted_tables: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset>>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, scalar_key_sorted_tables); } + #[inline] pub fn add_native_inline(&mut self, native_inline: &Test) { self.fbb_.push_slot_always::<&Test>(Monster::VT_NATIVE_INLINE, native_inline); } + #[inline] pub fn add_long_enum_non_enum_default(&mut self, long_enum_non_enum_default: LongEnum) { self.fbb_.push_slot::(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, long_enum_non_enum_default, Default::default()); } + #[inline] pub fn add_long_enum_normal_default(&mut self, long_enum_normal_default: LongEnum) { self.fbb_.push_slot::(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, long_enum_normal_default, LongEnum::LongOne); } + #[inline] pub fn add_nan_default(&mut self, nan_default: f32) { self.fbb_.push_slot::(Monster::VT_NAN_DEFAULT, nan_default, f32::NAN); } + #[inline] pub fn add_inf_default(&mut self, inf_default: f32) { self.fbb_.push_slot::(Monster::VT_INF_DEFAULT, inf_default, f32::INFINITY); } + #[inline] pub fn add_positive_inf_default(&mut self, positive_inf_default: f32) { self.fbb_.push_slot::(Monster::VT_POSITIVE_INF_DEFAULT, positive_inf_default, f32::INFINITY); } + #[inline] pub fn add_infinity_default(&mut self, infinity_default: f32) { self.fbb_.push_slot::(Monster::VT_INFINITY_DEFAULT, infinity_default, f32::INFINITY); } + #[inline] pub fn add_positive_infinity_default(&mut self, positive_infinity_default: f32) { self.fbb_.push_slot::(Monster::VT_POSITIVE_INFINITY_DEFAULT, positive_infinity_default, f32::INFINITY); } + #[inline] pub fn add_negative_inf_default(&mut self, negative_inf_default: f32) { self.fbb_.push_slot::(Monster::VT_NEGATIVE_INF_DEFAULT, negative_inf_default, f32::NEG_INFINITY); } + #[inline] pub fn add_negative_infinity_default(&mut self, negative_infinity_default: f32) { self.fbb_.push_slot::(Monster::VT_NEGATIVE_INFINITY_DEFAULT, negative_infinity_default, f32::NEG_INFINITY); } + #[inline] pub fn add_double_inf_default(&mut self, double_inf_default: f64) { self.fbb_.push_slot::(Monster::VT_DOUBLE_INF_DEFAULT, double_inf_default, f64::INFINITY); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> MonsterBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -1686,6 +1816,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -1839,6 +1970,7 @@ impl ::core::fmt::Debug for Monster<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MonsterT { @@ -1901,6 +2033,7 @@ pub struct MonsterT { pub negative_infinity_default: f32, pub double_inf_default: f64, } + impl Default for MonsterT { fn default() -> Self { Self { @@ -1965,6 +2098,7 @@ impl Default for MonsterT { } } } + impl MonsterT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, @@ -2147,66 +2281,73 @@ impl MonsterT { }) } } -#[inline] + /// Verifies that a buffer of bytes contains a `Monster` /// and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. +#[inline] pub fn root_as_monster(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::root::(buf) } -#[inline] + /// Verifies that a buffer of bytes contains a size prefixed /// `Monster` and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_monster_unchecked`. +#[inline] pub fn size_prefixed_root_as_monster(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::size_prefixed_root::(buf) } -#[inline] + /// Verifies, with the given options, that a buffer of bytes /// contains a `Monster` and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. +#[inline] pub fn root_as_monster_with_opts<'b, 'o>( opts: &'o ::flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::root_with_opts::>(opts, buf) } -#[inline] + /// Verifies, with the given verifier options, that a buffer of /// bytes contains a size prefixed `Monster` and returns /// it. Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_monster_unchecked`. +#[inline] pub fn size_prefixed_root_as_monster_with_opts<'b, 'o>( opts: &'o ::flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } -#[inline] + /// Assumes, without verification, that a buffer of bytes contains a Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `Monster`. +#[inline] pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { ::flatbuffers::root_unchecked::(buf) } } -#[inline] + /// Assumes, without verification, that a buffer of bytes contains a size prefixed Monster and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `Monster`. +#[inline] pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster<'_> { unsafe { ::flatbuffers::size_prefixed_root_unchecked::(buf) } } + pub const MONSTER_IDENTIFIER: &str = "MONS"; #[inline] 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..1f6de1d4e19 100644 --- a/tests/monster_test_serialize/my_game/example/race_generated.rs +++ b/tests/monster_test_serialize/my_game/example/race_generated.rs @@ -4,10 +4,13 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_RACE: i8 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_RACE: [Race; 4] = [ @@ -20,6 +23,7 @@ pub const ENUM_VALUES_RACE: [Race; 4] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct Race(pub i8); + #[allow(non_upper_case_globals)] impl Race { pub const None: Self = Self(-1); @@ -35,6 +39,7 @@ impl Race { Self::Dwarf, Self::Elf, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -46,6 +51,7 @@ impl Race { } } } + impl ::core::fmt::Debug for Race { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -55,6 +61,7 @@ impl ::core::fmt::Debug for Race { } } } + impl Serialize for Race { fn serialize(&self, serializer: S) -> Result where @@ -85,6 +92,7 @@ impl<'de> serde::Deserialize<'de> for Race { impl<'a> ::flatbuffers::Follow<'a> for Race { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -94,6 +102,7 @@ impl<'a> ::flatbuffers::Follow<'a> for Race { impl ::flatbuffers::Push for Race { type Output = Race; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -102,10 +111,12 @@ impl ::flatbuffers::Push for Race { impl ::flatbuffers::EndianScalar for Race { type Scalar = i8; + #[inline] fn to_little_endian(self) -> i8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i8) -> Self { 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..c861df0d2d1 100644 --- a/tests/monster_test_serialize/my_game/example/referrable_generated.rs +++ b/tests/monster_test_serialize/my_game/example/referrable_generated.rs @@ -4,15 +4,17 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + pub enum ReferrableOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct Referrable<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Referrable<'a> { type Inner = Referrable<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -30,6 +32,7 @@ impl<'a> Referrable<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Referrable { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -54,6 +57,7 @@ impl<'a> Referrable<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Referrable::VT_ID, Some(0)).unwrap()} } + #[inline] pub fn key_compare_less_than(&self, o: &Referrable) -> bool { self.id() < o.id() @@ -77,9 +81,11 @@ impl ::flatbuffers::Verifiable for Referrable<'_> { Ok(()) } } + pub struct ReferrableArgs { pub id: u64, } + impl<'a> Default for ReferrableArgs { #[inline] fn default() -> Self { @@ -104,11 +110,13 @@ pub struct ReferrableBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> ReferrableBuilder<'a, 'b, A> { #[inline] pub fn add_id(&mut self, id: u64) { self.fbb_.push_slot::(Referrable::VT_ID, id, 0); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> ReferrableBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -117,6 +125,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> ReferrableBuilder<'a, 'b, A> start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -131,11 +140,13 @@ impl ::core::fmt::Debug for Referrable<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct ReferrableT { pub id: u64, } + impl Default for ReferrableT { fn default() -> Self { Self { @@ -143,6 +154,7 @@ impl Default for ReferrableT { } } } + impl ReferrableT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..1d4d43f73fc 100644 --- a/tests/monster_test_serialize/my_game/example/stat_generated.rs +++ b/tests/monster_test_serialize/my_game/example/stat_generated.rs @@ -4,15 +4,17 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + pub enum StatOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct Stat<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Stat<'a> { type Inner = Stat<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -32,6 +34,7 @@ impl<'a> Stat<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Stat { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -64,6 +67,7 @@ impl<'a> Stat<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)} } + #[inline] pub fn val(&self) -> i64 { // Safety: @@ -71,6 +75,7 @@ impl<'a> Stat<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Stat::VT_VAL, Some(0)).unwrap()} } + #[inline] pub fn count(&self) -> u16 { // Safety: @@ -78,6 +83,7 @@ impl<'a> Stat<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(Stat::VT_COUNT, Some(0)).unwrap()} } + #[inline] pub fn key_compare_less_than(&self, o: &Stat) -> bool { self.count() < o.count() @@ -103,11 +109,13 @@ impl ::flatbuffers::Verifiable for Stat<'_> { Ok(()) } } + pub struct StatArgs<'a> { pub id: Option<::flatbuffers::WIPOffset<&'a str>>, pub val: i64, pub count: u16, } + impl<'a> Default for StatArgs<'a> { #[inline] fn default() -> Self { @@ -140,19 +148,23 @@ pub struct StatBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> StatBuilder<'a, 'b, A> { #[inline] pub fn add_id(&mut self, id: ::flatbuffers::WIPOffset<&'b str>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Stat::VT_ID, id); } + #[inline] pub fn add_val(&mut self, val: i64) { self.fbb_.push_slot::(Stat::VT_VAL, val, 0); } + #[inline] pub fn add_count(&mut self, count: u16) { self.fbb_.push_slot::(Stat::VT_COUNT, count, 0); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> StatBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -161,6 +173,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> StatBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -177,6 +190,7 @@ impl ::core::fmt::Debug for Stat<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct StatT { @@ -184,6 +198,7 @@ pub struct StatT { pub val: i64, pub count: u16, } + impl Default for StatT { fn default() -> Self { Self { @@ -193,6 +208,7 @@ impl Default for StatT { } } } + impl StatT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..87065624307 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 @@ -4,15 +4,18 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + // struct StructOfStructs, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct StructOfStructs(pub [u8; 20]); + impl Default for StructOfStructs { fn default() -> Self { Self([0; 20]) } } + impl ::core::fmt::Debug for StructOfStructs { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("StructOfStructs") @@ -24,27 +27,34 @@ impl ::core::fmt::Debug for StructOfStructs { } impl ::flatbuffers::SimpleToVerifyInSlice for StructOfStructs {} + impl<'a> ::flatbuffers::Follow<'a> for StructOfStructs { type Inner = &'a StructOfStructs; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a StructOfStructs>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a StructOfStructs { type Inner = &'a StructOfStructs; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for StructOfStructs { type Output = StructOfStructs; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -142,6 +152,7 @@ pub struct StructOfStructsT { pub b: TestT, pub c: AbilityT, } + impl StructOfStructsT { pub fn pack(&self) -> StructOfStructs { StructOfStructs::new( @@ -151,4 +162,3 @@ impl StructOfStructsT { ) } } - 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..dae0180a6ee 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 @@ -4,15 +4,18 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + // struct StructOfStructsOfStructs, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct StructOfStructsOfStructs(pub [u8; 20]); + impl Default for StructOfStructsOfStructs { fn default() -> Self { Self([0; 20]) } } + impl ::core::fmt::Debug for StructOfStructsOfStructs { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("StructOfStructsOfStructs") @@ -22,27 +25,34 @@ impl ::core::fmt::Debug for StructOfStructsOfStructs { } impl ::flatbuffers::SimpleToVerifyInSlice for StructOfStructsOfStructs {} + impl<'a> ::flatbuffers::Follow<'a> for StructOfStructsOfStructs { type Inner = &'a StructOfStructsOfStructs; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a StructOfStructsOfStructs>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a StructOfStructsOfStructs { type Inner = &'a StructOfStructsOfStructs; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for StructOfStructsOfStructs { type Output = StructOfStructsOfStructs; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -106,6 +116,7 @@ impl<'a> StructOfStructsOfStructs { pub struct StructOfStructsOfStructsT { pub a: StructOfStructsT, } + impl StructOfStructsOfStructsT { pub fn pack(&self) -> StructOfStructsOfStructs { StructOfStructsOfStructs::new( @@ -113,4 +124,3 @@ impl StructOfStructsOfStructsT { ) } } - 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..b1e4e2c9234 100644 --- a/tests/monster_test_serialize/my_game/example/test_generated.rs +++ b/tests/monster_test_serialize/my_game/example/test_generated.rs @@ -4,15 +4,18 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + // struct Test, aligned to 2 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Test(pub [u8; 4]); + impl Default for Test { fn default() -> Self { Self([0; 4]) } } + impl ::core::fmt::Debug for Test { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Test") @@ -23,27 +26,34 @@ impl ::core::fmt::Debug for Test { } impl ::flatbuffers::SimpleToVerifyInSlice for Test {} + impl<'a> ::flatbuffers::Follow<'a> for Test { type Inner = &'a Test; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Test>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Test { type Inner = &'a Test; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Test { type Output = Test; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Test as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(2) @@ -158,6 +168,7 @@ pub struct TestT { pub a: i16, pub b: i8, } + impl TestT { pub fn pack(&self) -> Test { Test::new( @@ -166,4 +177,3 @@ impl TestT { ) } } - 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..c55e1cb1e23 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 @@ -4,15 +4,17 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + pub enum TestSimpleTableWithEnumOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TestSimpleTableWithEnum<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> { type Inner = TestSimpleTableWithEnum<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -30,6 +32,7 @@ impl<'a> TestSimpleTableWithEnum<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TestSimpleTableWithEnum { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -67,9 +70,11 @@ impl ::flatbuffers::Verifiable for TestSimpleTableWithEnum<'_> { Ok(()) } } + pub struct TestSimpleTableWithEnumArgs { pub color: Color, } + impl<'a> Default for TestSimpleTableWithEnumArgs { #[inline] fn default() -> Self { @@ -94,11 +99,13 @@ pub struct TestSimpleTableWithEnumBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocato fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TestSimpleTableWithEnumBuilder<'a, 'b, A> { #[inline] pub fn add_color(&mut self, color: Color) { self.fbb_.push_slot::(TestSimpleTableWithEnum::VT_COLOR, color, Color::Green); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TestSimpleTableWithEnumBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -107,6 +114,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TestSimpleTableWithEnumBuilde start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -121,11 +129,13 @@ impl ::core::fmt::Debug for TestSimpleTableWithEnum<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TestSimpleTableWithEnumT { pub color: Color, } + impl Default for TestSimpleTableWithEnumT { fn default() -> Self { Self { @@ -133,6 +143,7 @@ impl Default for TestSimpleTableWithEnumT { } } } + impl TestSimpleTableWithEnumT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..5c6393f15a9 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 @@ -4,15 +4,17 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + pub enum TypeAliasesOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TypeAliases<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TypeAliases<'a> { type Inner = TypeAliases<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -41,6 +43,7 @@ impl<'a> TypeAliases<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TypeAliases { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -102,6 +105,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_I8_, Some(0)).unwrap()} } + #[inline] pub fn u8_(&self) -> u8 { // Safety: @@ -109,6 +113,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_U8_, Some(0)).unwrap()} } + #[inline] pub fn i16_(&self) -> i16 { // Safety: @@ -116,6 +121,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_I16_, Some(0)).unwrap()} } + #[inline] pub fn u16_(&self) -> u16 { // Safety: @@ -123,6 +129,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_U16_, Some(0)).unwrap()} } + #[inline] pub fn i32_(&self) -> i32 { // Safety: @@ -130,6 +137,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_I32_, Some(0)).unwrap()} } + #[inline] pub fn u32_(&self) -> u32 { // Safety: @@ -137,6 +145,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_U32_, Some(0)).unwrap()} } + #[inline] pub fn i64_(&self) -> i64 { // Safety: @@ -144,6 +153,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_I64_, Some(0)).unwrap()} } + #[inline] pub fn u64_(&self) -> u64 { // Safety: @@ -151,6 +161,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_U64_, Some(0)).unwrap()} } + #[inline] pub fn f32_(&self) -> f32 { // Safety: @@ -158,6 +169,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_F32_, Some(0.0)).unwrap()} } + #[inline] pub fn f64_(&self) -> f64 { // Safety: @@ -165,6 +177,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TypeAliases::VT_F64_, Some(0.0)).unwrap()} } + #[inline] pub fn v8(&self) -> Option<::flatbuffers::Vector<'a, i8>> { // Safety: @@ -172,6 +185,7 @@ impl<'a> TypeAliases<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, i8>>>(TypeAliases::VT_V8, None)} } + #[inline] pub fn vf64(&self) -> Option<::flatbuffers::Vector<'a, f64>> { // Safety: @@ -203,6 +217,7 @@ impl ::flatbuffers::Verifiable for TypeAliases<'_> { Ok(()) } } + pub struct TypeAliasesArgs<'a> { pub i8_: i8, pub u8_: u8, @@ -217,6 +232,7 @@ pub struct TypeAliasesArgs<'a> { pub v8: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, i8>>>, pub vf64: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, f64>>>, } + impl<'a> Default for TypeAliasesArgs<'a> { #[inline] fn default() -> Self { @@ -271,55 +287,68 @@ pub struct TypeAliasesBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TypeAliasesBuilder<'a, 'b, A> { #[inline] pub fn add_i8_(&mut self, i8_: i8) { self.fbb_.push_slot::(TypeAliases::VT_I8_, i8_, 0); } + #[inline] pub fn add_u8_(&mut self, u8_: u8) { self.fbb_.push_slot::(TypeAliases::VT_U8_, u8_, 0); } + #[inline] pub fn add_i16_(&mut self, i16_: i16) { self.fbb_.push_slot::(TypeAliases::VT_I16_, i16_, 0); } + #[inline] pub fn add_u16_(&mut self, u16_: u16) { self.fbb_.push_slot::(TypeAliases::VT_U16_, u16_, 0); } + #[inline] pub fn add_i32_(&mut self, i32_: i32) { self.fbb_.push_slot::(TypeAliases::VT_I32_, i32_, 0); } + #[inline] pub fn add_u32_(&mut self, u32_: u32) { self.fbb_.push_slot::(TypeAliases::VT_U32_, u32_, 0); } + #[inline] pub fn add_i64_(&mut self, i64_: i64) { self.fbb_.push_slot::(TypeAliases::VT_I64_, i64_, 0); } + #[inline] pub fn add_u64_(&mut self, u64_: u64) { self.fbb_.push_slot::(TypeAliases::VT_U64_, u64_, 0); } + #[inline] pub fn add_f32_(&mut self, f32_: f32) { self.fbb_.push_slot::(TypeAliases::VT_F32_, f32_, 0.0); } + #[inline] pub fn add_f64_(&mut self, f64_: f64) { self.fbb_.push_slot::(TypeAliases::VT_F64_, f64_, 0.0); } + #[inline] pub fn add_v8(&mut self, v8: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , i8>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(TypeAliases::VT_V8, v8); } + #[inline] pub fn add_vf64(&mut self, vf64: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , f64>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(TypeAliases::VT_VF64, vf64); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TypeAliasesBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -328,6 +357,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TypeAliasesBuilder<'a, 'b, A> start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -353,6 +383,7 @@ impl ::core::fmt::Debug for TypeAliases<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TypeAliasesT { @@ -369,6 +400,7 @@ pub struct TypeAliasesT { pub v8: Option>, pub vf64: Option>, } + impl Default for TypeAliasesT { fn default() -> Self { Self { @@ -387,6 +419,7 @@ impl Default for TypeAliasesT { } } } + impl TypeAliasesT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &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..f92107d6d82 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 @@ -4,15 +4,18 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + // struct Vec3, aligned to 8 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Vec3(pub [u8; 32]); + impl Default for Vec3 { fn default() -> Self { Self([0; 32]) } } + impl ::core::fmt::Debug for Vec3 { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Vec3") @@ -27,27 +30,34 @@ impl ::core::fmt::Debug for Vec3 { } impl ::flatbuffers::SimpleToVerifyInSlice for Vec3 {} + impl<'a> ::flatbuffers::Follow<'a> for Vec3 { type Inner = &'a Vec3; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Vec3>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Vec3 { type Inner = &'a Vec3; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Vec3 { type Output = Vec3; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(8) @@ -281,6 +291,7 @@ pub struct Vec3T { pub test2: Color, pub test3: TestT, } + impl Vec3T { pub fn pack(&self) -> Vec3 { Vec3::new( @@ -293,4 +304,3 @@ impl Vec3T { ) } } - 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..cef325de8fc 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 @@ -4,15 +4,17 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + pub enum MonsterOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct Monster<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Monster<'a> { type Inner = Monster<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -20,7 +22,6 @@ impl<'a> ::flatbuffers::Follow<'a> for Monster<'a> { } impl<'a> Monster<'a> { - pub const fn get_fully_qualified_name() -> &'static str { "MyGame.Example2.Monster" } @@ -29,6 +30,7 @@ impl<'a> Monster<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Monster { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -54,8 +56,10 @@ impl ::flatbuffers::Verifiable for Monster<'_> { Ok(()) } } + pub struct MonsterArgs { } + impl<'a> Default for MonsterArgs { #[inline] fn default() -> Self { @@ -78,6 +82,7 @@ pub struct MonsterBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> { #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> MonsterBuilder<'a, 'b, A> { @@ -87,6 +92,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -100,16 +106,19 @@ impl ::core::fmt::Debug for Monster<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MonsterT { } + impl Default for MonsterT { fn default() -> Self { Self { } } } + impl MonsterT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..19d3fdf0b4c 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 @@ -4,15 +4,17 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + pub enum InParentNamespaceOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct InParentNamespace<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for InParentNamespace<'a> { type Inner = InParentNamespace<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -20,7 +22,6 @@ impl<'a> ::flatbuffers::Follow<'a> for InParentNamespace<'a> { } impl<'a> InParentNamespace<'a> { - pub const fn get_fully_qualified_name() -> &'static str { "MyGame.InParentNamespace" } @@ -29,6 +30,7 @@ impl<'a> InParentNamespace<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { InParentNamespace { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -54,8 +56,10 @@ impl ::flatbuffers::Verifiable for InParentNamespace<'_> { Ok(()) } } + pub struct InParentNamespaceArgs { } + impl<'a> Default for InParentNamespaceArgs { #[inline] fn default() -> Self { @@ -78,6 +82,7 @@ pub struct InParentNamespaceBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> InParentNamespaceBuilder<'a, 'b, A> { #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> InParentNamespaceBuilder<'a, 'b, A> { @@ -87,6 +92,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> InParentNamespaceBuilder<'a, start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -100,16 +106,19 @@ impl ::core::fmt::Debug for InParentNamespace<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct InParentNamespaceT { } + impl Default for InParentNamespaceT { fn default() -> Self { Self { } } } + impl InParentNamespaceT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..fb89543c768 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 @@ -4,10 +4,13 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_FROM_INCLUDE: i64 = 0; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ @@ -17,6 +20,7 @@ pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct FromInclude(pub i64); + #[allow(non_upper_case_globals)] impl FromInclude { pub const IncludeVal: Self = Self(0); @@ -26,6 +30,7 @@ impl FromInclude { pub const ENUM_VALUES: &'static [Self] = &[ Self::IncludeVal, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -34,6 +39,7 @@ impl FromInclude { } } } + impl ::core::fmt::Debug for FromInclude { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -43,6 +49,7 @@ impl ::core::fmt::Debug for FromInclude { } } } + impl Serialize for FromInclude { fn serialize(&self, serializer: S) -> Result where @@ -73,6 +80,7 @@ impl<'de> serde::Deserialize<'de> for FromInclude { impl<'a> ::flatbuffers::Follow<'a> for FromInclude { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -82,6 +90,7 @@ impl<'a> ::flatbuffers::Follow<'a> for FromInclude { impl ::flatbuffers::Push for FromInclude { type Output = FromInclude; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -90,10 +99,12 @@ impl ::flatbuffers::Push for FromInclude { impl ::flatbuffers::EndianScalar for FromInclude { type Scalar = i64; + #[inline] fn to_little_endian(self) -> i64 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i64) -> Self { 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..9a7eb88251e 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 @@ -4,15 +4,17 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + pub enum TableBOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableB<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableB<'a> { type Inner = TableB<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -30,6 +32,7 @@ impl<'a> TableB<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableB { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -69,9 +72,11 @@ impl ::flatbuffers::Verifiable for TableB<'_> { Ok(()) } } + pub struct TableBArgs<'a> { pub a: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableBArgs<'a> { #[inline] fn default() -> Self { @@ -100,11 +105,13 @@ pub struct TableBBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { #[inline] pub fn add_a(&mut self, a: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableB::VT_A, a); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableBBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -113,6 +120,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableBBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -127,11 +135,13 @@ impl ::core::fmt::Debug for TableB<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableBT { pub a: Option>, } + impl Default for TableBT { fn default() -> Self { Self { @@ -139,6 +149,7 @@ impl Default for TableBT { } } } + impl TableBT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &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..03491e295a9 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 @@ -4,15 +4,18 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + // struct Unused, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct Unused(pub [u8; 4]); + impl Default for Unused { fn default() -> Self { Self([0; 4]) } } + impl ::core::fmt::Debug for Unused { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Unused") @@ -22,27 +25,34 @@ impl ::core::fmt::Debug for Unused { } impl ::flatbuffers::SimpleToVerifyInSlice for Unused {} + impl<'a> ::flatbuffers::Follow<'a> for Unused { type Inner = &'a Unused; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Unused>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Unused { type Inner = &'a Unused; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Unused { type Output = Unused; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -123,6 +133,7 @@ impl<'a> Unused { pub struct UnusedT { pub a: i32, } + impl UnusedT { pub fn pack(&self) -> Unused { Unused::new( @@ -130,4 +141,3 @@ impl UnusedT { ) } } - diff --git a/tests/monster_test_serialize/table_a_generated.rs b/tests/monster_test_serialize/table_a_generated.rs index a3c1ba60886..1f8a7093ddd 100644 --- a/tests/monster_test_serialize/table_a_generated.rs +++ b/tests/monster_test_serialize/table_a_generated.rs @@ -4,15 +4,17 @@ extern crate alloc; extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeStruct}; use super::*; + pub enum TableAOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableA<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableA<'a> { type Inner = TableA<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -30,6 +32,7 @@ impl<'a> TableA<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableA { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -69,9 +72,11 @@ impl ::flatbuffers::Verifiable for TableA<'_> { Ok(()) } } + pub struct TableAArgs<'a> { pub b: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableAArgs<'a> { #[inline] fn default() -> Self { @@ -100,11 +105,13 @@ pub struct TableABuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { #[inline] pub fn add_b(&mut self, b: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableA::VT_B, b); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableABuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -113,6 +120,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableABuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -127,11 +135,13 @@ impl ::core::fmt::Debug for TableA<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableAT { pub b: Option>, } + impl Default for TableAT { fn default() -> Self { Self { @@ -139,6 +149,7 @@ impl Default for TableAT { } } } + impl TableAT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, diff --git a/tests/more_defaults/abc_generated.rs b/tests/more_defaults/abc_generated.rs index c41b406000b..a3c54fb5d9f 100644 --- a/tests/more_defaults/abc_generated.rs +++ b/tests/more_defaults/abc_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ABC: i32 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ABC: [ABC; 3] = [ @@ -17,6 +20,7 @@ pub const ENUM_VALUES_ABC: [ABC; 3] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct ABC(pub i32); + #[allow(non_upper_case_globals)] impl ABC { pub const A: Self = Self(0); @@ -30,6 +34,7 @@ impl ABC { Self::B, Self::C, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -40,6 +45,7 @@ impl ABC { } } } + impl ::core::fmt::Debug for ABC { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -49,8 +55,10 @@ impl ::core::fmt::Debug for ABC { } } } + impl<'a> ::flatbuffers::Follow<'a> for ABC { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -60,6 +68,7 @@ impl<'a> ::flatbuffers::Follow<'a> for ABC { impl ::flatbuffers::Push for ABC { type Output = ABC; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -68,10 +77,12 @@ impl ::flatbuffers::Push for ABC { impl ::flatbuffers::EndianScalar for ABC { type Scalar = i32; + #[inline] fn to_little_endian(self) -> i32 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i32) -> Self { diff --git a/tests/more_defaults/more_defaults_generated.rs b/tests/more_defaults/more_defaults_generated.rs index 72dd9dbcb63..784297cf581 100644 --- a/tests/more_defaults/more_defaults_generated.rs +++ b/tests/more_defaults/more_defaults_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum MoreDefaultsOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct MoreDefaults<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for MoreDefaults<'a> { type Inner = MoreDefaults<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -33,6 +35,7 @@ impl<'a> MoreDefaults<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { MoreDefaults { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -90,6 +93,7 @@ impl<'a> MoreDefaults<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, i32>>>(MoreDefaults::VT_INTS, Some(Default::default())).unwrap()} } + #[inline] pub fn floats(&self) -> ::flatbuffers::Vector<'a, f32> { // Safety: @@ -97,6 +101,7 @@ impl<'a> MoreDefaults<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, f32>>>(MoreDefaults::VT_FLOATS, Some(Default::default())).unwrap()} } + #[inline] pub fn empty_string(&self) -> &'a str { // Safety: @@ -104,6 +109,7 @@ impl<'a> MoreDefaults<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_EMPTY_STRING, Some(&"")).unwrap()} } + #[inline] pub fn some_string(&self) -> &'a str { // Safety: @@ -111,6 +117,7 @@ impl<'a> MoreDefaults<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_SOME_STRING, Some(&"some")).unwrap()} } + #[inline] pub fn abcs(&self) -> ::flatbuffers::Vector<'a, ABC> { // Safety: @@ -118,6 +125,7 @@ impl<'a> MoreDefaults<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ABC>>>(MoreDefaults::VT_ABCS, Some(Default::default())).unwrap()} } + #[inline] pub fn bools(&self) -> ::flatbuffers::Vector<'a, bool> { // Safety: @@ -143,6 +151,7 @@ impl ::flatbuffers::Verifiable for MoreDefaults<'_> { Ok(()) } } + pub struct MoreDefaultsArgs<'a> { pub ints: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, i32>>>, pub floats: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, f32>>>, @@ -151,6 +160,7 @@ pub struct MoreDefaultsArgs<'a> { pub abcs: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, ABC>>>, pub bools: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, bool>>>, } + impl<'a> Default for MoreDefaultsArgs<'a> { #[inline] fn default() -> Self { @@ -169,31 +179,38 @@ pub struct MoreDefaultsBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MoreDefaultsBuilder<'a, 'b, A> { #[inline] pub fn add_ints(&mut self, ints: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , i32>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(MoreDefaults::VT_INTS, ints); } + #[inline] pub fn add_floats(&mut self, floats: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , f32>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(MoreDefaults::VT_FLOATS, floats); } + #[inline] pub fn add_empty_string(&mut self, empty_string: ::flatbuffers::WIPOffset<&'b str>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(MoreDefaults::VT_EMPTY_STRING, empty_string); } + #[inline] pub fn add_some_string(&mut self, some_string: ::flatbuffers::WIPOffset<&'b str>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(MoreDefaults::VT_SOME_STRING, some_string); } + #[inline] pub fn add_abcs(&mut self, abcs: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ABC>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(MoreDefaults::VT_ABCS, abcs); } + #[inline] pub fn add_bools(&mut self, bools: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , bool>>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(MoreDefaults::VT_BOOLS, bools); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> MoreDefaultsBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -202,6 +219,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> MoreDefaultsBuilder<'a, 'b, A start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -221,6 +239,7 @@ impl ::core::fmt::Debug for MoreDefaults<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct MoreDefaultsT { @@ -231,6 +250,7 @@ pub struct MoreDefaultsT { pub abcs: alloc::vec::Vec, pub bools: alloc::vec::Vec, } + impl Default for MoreDefaultsT { fn default() -> Self { Self { @@ -243,6 +263,7 @@ impl Default for MoreDefaultsT { } } } + impl MoreDefaultsT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..54b79c197bb 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 @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ENUM_IN_NESTED_NS: i8 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ENUM_IN_NESTED_NS: [EnumInNestedNS; 3] = [ @@ -17,6 +20,7 @@ pub const ENUM_VALUES_ENUM_IN_NESTED_NS: [EnumInNestedNS; 3] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct EnumInNestedNS(pub i8); + #[allow(non_upper_case_globals)] impl EnumInNestedNS { pub const A: Self = Self(0); @@ -30,6 +34,7 @@ impl EnumInNestedNS { Self::B, Self::C, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -40,6 +45,7 @@ impl EnumInNestedNS { } } } + impl ::core::fmt::Debug for EnumInNestedNS { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -49,8 +55,10 @@ impl ::core::fmt::Debug for EnumInNestedNS { } } } + impl<'a> ::flatbuffers::Follow<'a> for EnumInNestedNS { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -60,6 +68,7 @@ impl<'a> ::flatbuffers::Follow<'a> for EnumInNestedNS { impl ::flatbuffers::Push for EnumInNestedNS { type Output = EnumInNestedNS; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -68,10 +77,12 @@ impl ::flatbuffers::Push for EnumInNestedNS { impl ::flatbuffers::EndianScalar for EnumInNestedNS { type Scalar = i8; + #[inline] fn to_little_endian(self) -> i8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i8) -> Self { 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..75d1909ba37 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 @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct StructInNestedNS, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct StructInNestedNS(pub [u8; 8]); + impl Default for StructInNestedNS { fn default() -> Self { Self([0; 8]) } } + impl ::core::fmt::Debug for StructInNestedNS { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("StructInNestedNS") @@ -21,27 +24,34 @@ impl ::core::fmt::Debug for StructInNestedNS { } impl ::flatbuffers::SimpleToVerifyInSlice for StructInNestedNS {} + impl<'a> ::flatbuffers::Follow<'a> for StructInNestedNS { type Inner = &'a StructInNestedNS; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a StructInNestedNS>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a StructInNestedNS { type Inner = &'a StructInNestedNS; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for StructInNestedNS { type Output = StructInNestedNS; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -144,6 +154,7 @@ pub struct StructInNestedNST { pub a: i32, pub b: i32, } + impl StructInNestedNST { pub fn pack(&self) -> StructInNestedNS { StructInNestedNS::new( @@ -152,4 +163,3 @@ impl StructInNestedNST { ) } } - 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..856ae6e4203 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TableInNestedNSOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableInNestedNS<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableInNestedNS<'a> { type Inner = TableInNestedNS<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> TableInNestedNS<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableInNestedNS { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -65,9 +68,11 @@ impl ::flatbuffers::Verifiable for TableInNestedNS<'_> { Ok(()) } } + pub struct TableInNestedNSArgs { pub foo: i32, } + impl<'a> Default for TableInNestedNSArgs { #[inline] fn default() -> Self { @@ -81,11 +86,13 @@ pub struct TableInNestedNSBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableInNestedNSBuilder<'a, 'b, A> { #[inline] pub fn add_foo(&mut self, foo: i32) { self.fbb_.push_slot::(TableInNestedNS::VT_FOO, foo, 0); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableInNestedNSBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -94,6 +101,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableInNestedNSBuilder<'a, 'b start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -108,11 +116,13 @@ impl ::core::fmt::Debug for TableInNestedNS<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableInNestedNST { pub foo: i32, } + impl Default for TableInNestedNST { fn default() -> Self { Self { @@ -120,6 +130,7 @@ impl Default for TableInNestedNST { } } } + impl TableInNestedNST { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..87ea03afce7 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 @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_UNION_IN_NESTED_NS: u8 = 1; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_UNION_IN_NESTED_NS: [UnionInNestedNS; 2] = [ @@ -16,6 +19,7 @@ pub const ENUM_VALUES_UNION_IN_NESTED_NS: [UnionInNestedNS; 2] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct UnionInNestedNS(pub u8); + #[allow(non_upper_case_globals)] impl UnionInNestedNS { pub const NONE: Self = Self(0); @@ -27,6 +31,7 @@ impl UnionInNestedNS { Self::NONE, Self::TableInNestedNS, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -36,6 +41,7 @@ impl UnionInNestedNS { } } } + impl ::core::fmt::Debug for UnionInNestedNS { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -45,8 +51,10 @@ impl ::core::fmt::Debug for UnionInNestedNS { } } } + impl<'a> ::flatbuffers::Follow<'a> for UnionInNestedNS { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -56,6 +64,7 @@ impl<'a> ::flatbuffers::Follow<'a> for UnionInNestedNS { impl ::flatbuffers::Push for UnionInNestedNS { type Output = UnionInNestedNS; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -64,10 +73,12 @@ impl ::flatbuffers::Push for UnionInNestedNS { impl ::flatbuffers::EndianScalar for UnionInNestedNS { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -86,6 +97,7 @@ impl<'a> ::flatbuffers::Verifiable for UnionInNestedNS { } impl ::flatbuffers::SimpleToVerifyInSlice for UnionInNestedNS {} + pub struct UnionInNestedNSUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -95,11 +107,13 @@ pub enum UnionInNestedNST { NONE, TableInNestedNS(alloc::boxed::Box), } + impl Default for UnionInNestedNST { fn default() -> Self { Self::NONE } } + impl UnionInNestedNST { pub fn union_in_nested_ns_type(&self) -> UnionInNestedNS { match self { @@ -107,12 +121,14 @@ impl UnionInNestedNST { Self::TableInNestedNS(_) => UnionInNestedNS::TableInNestedNS, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, Self::TableInNestedNS(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned TableInNestedNST, setting the union to NONE. pub fn take_table_in_nested_ns(&mut self) -> Option> { if let Self::TableInNestedNS(_) = self { @@ -126,12 +142,15 @@ impl UnionInNestedNST { None } } + /// If the union variant matches, return a reference to the TableInNestedNST. pub fn as_table_in_nested_ns(&self) -> Option<&TableInNestedNST> { if let Self::TableInNestedNS(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the TableInNestedNST. pub fn as_table_in_nested_ns_mut(&mut self) -> Option<&mut TableInNestedNST> { if let Self::TableInNestedNS(v) = self { Some(v.as_mut()) } else { None } } } + 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..2e3004523a8 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum SecondTableInAOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct SecondTableInA<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for SecondTableInA<'a> { type Inner = SecondTableInA<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> SecondTableInA<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { SecondTableInA { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -67,9 +70,11 @@ impl ::flatbuffers::Verifiable for SecondTableInA<'_> { Ok(()) } } + pub struct SecondTableInAArgs<'a> { pub refer_to_c: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for SecondTableInAArgs<'a> { #[inline] fn default() -> Self { @@ -83,11 +88,13 @@ pub struct SecondTableInABuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> SecondTableInABuilder<'a, 'b, A> { #[inline] pub fn add_refer_to_c(&mut self, refer_to_c: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(SecondTableInA::VT_REFER_TO_C, refer_to_c); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> SecondTableInABuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -96,6 +103,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> SecondTableInABuilder<'a, 'b, start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -110,11 +118,13 @@ impl ::core::fmt::Debug for SecondTableInA<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct SecondTableInAT { pub refer_to_c: Option>, } + impl Default for SecondTableInAT { fn default() -> Self { Self { @@ -122,6 +132,7 @@ impl Default for SecondTableInAT { } } } + impl SecondTableInAT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &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..3ff5ee2ac19 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TableInFirstNSOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableInFirstNS<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableInFirstNS<'a> { type Inner = TableInFirstNS<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -32,6 +34,7 @@ impl<'a> TableInFirstNS<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableInFirstNS { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -78,6 +81,7 @@ impl<'a> TableInFirstNS<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(TableInFirstNS::VT_FOO_TABLE, None)} } + #[inline] pub fn foo_enum(&self) -> namespace_b::EnumInNestedNS { // Safety: @@ -85,6 +89,7 @@ impl<'a> TableInFirstNS<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TableInFirstNS::VT_FOO_ENUM, Some(namespace_b::EnumInNestedNS::A)).unwrap()} } + #[inline] pub fn foo_union_type(&self) -> namespace_b::UnionInNestedNS { // Safety: @@ -92,6 +97,7 @@ impl<'a> TableInFirstNS<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TableInFirstNS::VT_FOO_UNION_TYPE, Some(namespace_b::UnionInNestedNS::NONE)).unwrap()} } + #[inline] pub fn foo_union(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -99,6 +105,7 @@ impl<'a> TableInFirstNS<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(TableInFirstNS::VT_FOO_UNION, None)} } + #[inline] pub fn foo_struct(&self) -> Option<&'a namespace_b::StructInNestedNS> { // Safety: @@ -106,6 +113,7 @@ impl<'a> TableInFirstNS<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(TableInFirstNS::VT_FOO_STRUCT, None)} } + #[inline] #[allow(non_snake_case)] pub fn foo_union_as_table_in_nested_ns(&self) -> Option> { @@ -120,7 +128,6 @@ impl<'a> TableInFirstNS<'a> { None } } - } impl ::flatbuffers::Verifiable for TableInFirstNS<'_> { @@ -142,6 +149,7 @@ impl ::flatbuffers::Verifiable for TableInFirstNS<'_> { Ok(()) } } + pub struct TableInFirstNSArgs<'a> { pub foo_table: Option<::flatbuffers::WIPOffset>>, pub foo_enum: namespace_b::EnumInNestedNS, @@ -149,6 +157,7 @@ pub struct TableInFirstNSArgs<'a> { pub foo_union: Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>>, pub foo_struct: Option<&'a namespace_b::StructInNestedNS>, } + impl<'a> Default for TableInFirstNSArgs<'a> { #[inline] fn default() -> Self { @@ -166,27 +175,33 @@ pub struct TableInFirstNSBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableInFirstNSBuilder<'a, 'b, A> { #[inline] pub fn add_foo_table(&mut self, foo_table: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableInFirstNS::VT_FOO_TABLE, foo_table); } + #[inline] pub fn add_foo_enum(&mut self, foo_enum: namespace_b::EnumInNestedNS) { self.fbb_.push_slot::(TableInFirstNS::VT_FOO_ENUM, foo_enum, namespace_b::EnumInNestedNS::A); } + #[inline] pub fn add_foo_union_type(&mut self, foo_union_type: namespace_b::UnionInNestedNS) { self.fbb_.push_slot::(TableInFirstNS::VT_FOO_UNION_TYPE, foo_union_type, namespace_b::UnionInNestedNS::NONE); } + #[inline] pub fn add_foo_union(&mut self, foo_union: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(TableInFirstNS::VT_FOO_UNION, foo_union); } + #[inline] pub fn add_foo_struct(&mut self, foo_struct: &namespace_b::StructInNestedNS) { self.fbb_.push_slot_always::<&namespace_b::StructInNestedNS>(TableInFirstNS::VT_FOO_STRUCT, foo_struct); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableInFirstNSBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -195,6 +210,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableInFirstNSBuilder<'a, 'b, start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -225,6 +241,7 @@ impl ::core::fmt::Debug for TableInFirstNS<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableInFirstNST { @@ -233,6 +250,7 @@ pub struct TableInFirstNST { pub foo_union: namespace_b::UnionInNestedNST, pub foo_struct: Option, } + impl Default for TableInFirstNST { fn default() -> Self { Self { @@ -243,6 +261,7 @@ impl Default for TableInFirstNST { } } } + impl TableInFirstNST { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..df3c80e957a 100644 --- a/tests/namespace_test/namespace_c/table_in_c_generated.rs +++ b/tests/namespace_test/namespace_c/table_in_c_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum TableInCOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct TableInC<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for TableInC<'a> { type Inner = TableInC<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -29,6 +31,7 @@ impl<'a> TableInC<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { TableInC { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -60,6 +63,7 @@ impl<'a> TableInC<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset>(TableInC::VT_REFER_TO_A1, None)} } + #[inline] pub fn refer_to_a2(&self) -> Option> { // Safety: @@ -81,10 +85,12 @@ impl ::flatbuffers::Verifiable for TableInC<'_> { Ok(()) } } + pub struct TableInCArgs<'a> { pub refer_to_a1: Option<::flatbuffers::WIPOffset>>, pub refer_to_a2: Option<::flatbuffers::WIPOffset>>, } + impl<'a> Default for TableInCArgs<'a> { #[inline] fn default() -> Self { @@ -99,15 +105,18 @@ pub struct TableInCBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableInCBuilder<'a, 'b, A> { #[inline] pub fn add_refer_to_a1(&mut self, refer_to_a1: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableInC::VT_REFER_TO_A1, refer_to_a1); } + #[inline] pub fn add_refer_to_a2(&mut self, refer_to_a2: ::flatbuffers::WIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset>(TableInC::VT_REFER_TO_A2, refer_to_a2); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableInCBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -116,6 +125,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableInCBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -131,12 +141,14 @@ impl ::core::fmt::Debug for TableInC<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct TableInCT { pub refer_to_a1: Option>, pub refer_to_a2: Option>, } + impl Default for TableInCT { fn default() -> Self { Self { @@ -145,6 +157,7 @@ impl Default for TableInCT { } } } + impl TableInCT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &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..72026c4078a 100644 --- a/tests/optional_scalars/optional_scalars/optional_byte_generated.rs +++ b/tests/optional_scalars/optional_scalars/optional_byte_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_OPTIONAL_BYTE: i8 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_OPTIONAL_BYTE: [OptionalByte; 3] = [ @@ -17,6 +20,7 @@ pub const ENUM_VALUES_OPTIONAL_BYTE: [OptionalByte; 3] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct OptionalByte(pub i8); + #[allow(non_upper_case_globals)] impl OptionalByte { pub const None: Self = Self(0); @@ -30,6 +34,7 @@ impl OptionalByte { Self::One, Self::Two, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -40,6 +45,7 @@ impl OptionalByte { } } } + impl ::core::fmt::Debug for OptionalByte { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -49,8 +55,10 @@ impl ::core::fmt::Debug for OptionalByte { } } } + impl<'a> ::flatbuffers::Follow<'a> for OptionalByte { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -60,6 +68,7 @@ impl<'a> ::flatbuffers::Follow<'a> for OptionalByte { impl ::flatbuffers::Push for OptionalByte { type Output = OptionalByte; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -68,10 +77,12 @@ impl ::flatbuffers::Push for OptionalByte { impl ::flatbuffers::EndianScalar for OptionalByte { type Scalar = i8; + #[inline] fn to_little_endian(self) -> i8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i8) -> Self { diff --git a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs index 79052ff4b1f..fe3d8fe69e4 100644 --- a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs +++ b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum ScalarStuffOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct ScalarStuff<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for ScalarStuff<'a> { type Inner = ScalarStuff<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -63,6 +65,7 @@ impl<'a> ScalarStuff<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { ScalarStuff { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -192,6 +195,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_I8, Some(0)).unwrap()} } + #[inline] pub fn maybe_i8(&self) -> Option { // Safety: @@ -199,6 +203,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_I8, None)} } + #[inline] pub fn default_i8(&self) -> i8 { // Safety: @@ -206,6 +211,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_I8, Some(42)).unwrap()} } + #[inline] pub fn just_u8(&self) -> u8 { // Safety: @@ -213,6 +219,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_U8, Some(0)).unwrap()} } + #[inline] pub fn maybe_u8(&self) -> Option { // Safety: @@ -220,6 +227,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_U8, None)} } + #[inline] pub fn default_u8(&self) -> u8 { // Safety: @@ -227,6 +235,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_U8, Some(42)).unwrap()} } + #[inline] pub fn just_i16(&self) -> i16 { // Safety: @@ -234,6 +243,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_I16, Some(0)).unwrap()} } + #[inline] pub fn maybe_i16(&self) -> Option { // Safety: @@ -241,6 +251,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_I16, None)} } + #[inline] pub fn default_i16(&self) -> i16 { // Safety: @@ -248,6 +259,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_I16, Some(42)).unwrap()} } + #[inline] pub fn just_u16(&self) -> u16 { // Safety: @@ -255,6 +267,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_U16, Some(0)).unwrap()} } + #[inline] pub fn maybe_u16(&self) -> Option { // Safety: @@ -262,6 +275,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_U16, None)} } + #[inline] pub fn default_u16(&self) -> u16 { // Safety: @@ -269,6 +283,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_U16, Some(42)).unwrap()} } + #[inline] pub fn just_i32(&self) -> i32 { // Safety: @@ -276,6 +291,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_I32, Some(0)).unwrap()} } + #[inline] pub fn maybe_i32(&self) -> Option { // Safety: @@ -283,6 +299,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_I32, None)} } + #[inline] pub fn default_i32(&self) -> i32 { // Safety: @@ -290,6 +307,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_I32, Some(42)).unwrap()} } + #[inline] pub fn just_u32(&self) -> u32 { // Safety: @@ -297,6 +315,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_U32, Some(0)).unwrap()} } + #[inline] pub fn maybe_u32(&self) -> Option { // Safety: @@ -304,6 +323,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_U32, None)} } + #[inline] pub fn default_u32(&self) -> u32 { // Safety: @@ -311,6 +331,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_U32, Some(42)).unwrap()} } + #[inline] pub fn just_i64(&self) -> i64 { // Safety: @@ -318,6 +339,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_I64, Some(0)).unwrap()} } + #[inline] pub fn maybe_i64(&self) -> Option { // Safety: @@ -325,6 +347,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_I64, None)} } + #[inline] pub fn default_i64(&self) -> i64 { // Safety: @@ -332,6 +355,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_I64, Some(42)).unwrap()} } + #[inline] pub fn just_u64(&self) -> u64 { // Safety: @@ -339,6 +363,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_U64, Some(0)).unwrap()} } + #[inline] pub fn maybe_u64(&self) -> Option { // Safety: @@ -346,6 +371,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_U64, None)} } + #[inline] pub fn default_u64(&self) -> u64 { // Safety: @@ -353,6 +379,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_U64, Some(42)).unwrap()} } + #[inline] pub fn just_f32(&self) -> f32 { // Safety: @@ -360,6 +387,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_F32, Some(0.0)).unwrap()} } + #[inline] pub fn maybe_f32(&self) -> Option { // Safety: @@ -367,6 +395,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_F32, None)} } + #[inline] pub fn default_f32(&self) -> f32 { // Safety: @@ -374,6 +403,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_F32, Some(42.0)).unwrap()} } + #[inline] pub fn just_f64(&self) -> f64 { // Safety: @@ -381,6 +411,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_F64, Some(0.0)).unwrap()} } + #[inline] pub fn maybe_f64(&self) -> Option { // Safety: @@ -388,6 +419,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_F64, None)} } + #[inline] pub fn default_f64(&self) -> f64 { // Safety: @@ -395,6 +427,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_F64, Some(42.0)).unwrap()} } + #[inline] pub fn just_bool(&self) -> bool { // Safety: @@ -402,6 +435,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_BOOL, Some(false)).unwrap()} } + #[inline] pub fn maybe_bool(&self) -> Option { // Safety: @@ -409,6 +443,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_BOOL, None)} } + #[inline] pub fn default_bool(&self) -> bool { // Safety: @@ -416,6 +451,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_DEFAULT_BOOL, Some(true)).unwrap()} } + #[inline] pub fn just_enum(&self) -> OptionalByte { // Safety: @@ -423,6 +459,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_JUST_ENUM, Some(OptionalByte::None)).unwrap()} } + #[inline] pub fn maybe_enum(&self) -> Option { // Safety: @@ -430,6 +467,7 @@ impl<'a> ScalarStuff<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(ScalarStuff::VT_MAYBE_ENUM, None)} } + #[inline] pub fn default_enum(&self) -> OptionalByte { // Safety: @@ -485,6 +523,7 @@ impl ::flatbuffers::Verifiable for ScalarStuff<'_> { Ok(()) } } + pub struct ScalarStuffArgs { pub just_i8: i8, pub maybe_i8: Option, @@ -523,6 +562,7 @@ pub struct ScalarStuffArgs { pub maybe_enum: Option, pub default_enum: OptionalByte, } + impl<'a> Default for ScalarStuffArgs { #[inline] fn default() -> Self { @@ -571,151 +611,188 @@ pub struct ScalarStuffBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> ScalarStuffBuilder<'a, 'b, A> { #[inline] pub fn add_just_i8(&mut self, just_i8: i8) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_I8, just_i8, 0); } + #[inline] pub fn add_maybe_i8(&mut self, maybe_i8: i8) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_I8, maybe_i8); } + #[inline] pub fn add_default_i8(&mut self, default_i8: i8) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_I8, default_i8, 42); } + #[inline] pub fn add_just_u8(&mut self, just_u8: u8) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_U8, just_u8, 0); } + #[inline] pub fn add_maybe_u8(&mut self, maybe_u8: u8) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_U8, maybe_u8); } + #[inline] pub fn add_default_u8(&mut self, default_u8: u8) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_U8, default_u8, 42); } + #[inline] pub fn add_just_i16(&mut self, just_i16: i16) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_I16, just_i16, 0); } + #[inline] pub fn add_maybe_i16(&mut self, maybe_i16: i16) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_I16, maybe_i16); } + #[inline] pub fn add_default_i16(&mut self, default_i16: i16) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_I16, default_i16, 42); } + #[inline] pub fn add_just_u16(&mut self, just_u16: u16) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_U16, just_u16, 0); } + #[inline] pub fn add_maybe_u16(&mut self, maybe_u16: u16) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_U16, maybe_u16); } + #[inline] pub fn add_default_u16(&mut self, default_u16: u16) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_U16, default_u16, 42); } + #[inline] pub fn add_just_i32(&mut self, just_i32: i32) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_I32, just_i32, 0); } + #[inline] pub fn add_maybe_i32(&mut self, maybe_i32: i32) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_I32, maybe_i32); } + #[inline] pub fn add_default_i32(&mut self, default_i32: i32) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_I32, default_i32, 42); } + #[inline] pub fn add_just_u32(&mut self, just_u32: u32) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_U32, just_u32, 0); } + #[inline] pub fn add_maybe_u32(&mut self, maybe_u32: u32) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_U32, maybe_u32); } + #[inline] pub fn add_default_u32(&mut self, default_u32: u32) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_U32, default_u32, 42); } + #[inline] pub fn add_just_i64(&mut self, just_i64: i64) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_I64, just_i64, 0); } + #[inline] pub fn add_maybe_i64(&mut self, maybe_i64: i64) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_I64, maybe_i64); } + #[inline] pub fn add_default_i64(&mut self, default_i64: i64) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_I64, default_i64, 42); } + #[inline] pub fn add_just_u64(&mut self, just_u64: u64) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_U64, just_u64, 0); } + #[inline] pub fn add_maybe_u64(&mut self, maybe_u64: u64) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_U64, maybe_u64); } + #[inline] pub fn add_default_u64(&mut self, default_u64: u64) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_U64, default_u64, 42); } + #[inline] pub fn add_just_f32(&mut self, just_f32: f32) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_F32, just_f32, 0.0); } + #[inline] pub fn add_maybe_f32(&mut self, maybe_f32: f32) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_F32, maybe_f32); } + #[inline] pub fn add_default_f32(&mut self, default_f32: f32) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_F32, default_f32, 42.0); } + #[inline] pub fn add_just_f64(&mut self, just_f64: f64) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_F64, just_f64, 0.0); } + #[inline] pub fn add_maybe_f64(&mut self, maybe_f64: f64) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_F64, maybe_f64); } + #[inline] pub fn add_default_f64(&mut self, default_f64: f64) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_F64, default_f64, 42.0); } + #[inline] pub fn add_just_bool(&mut self, just_bool: bool) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_BOOL, just_bool, false); } + #[inline] pub fn add_maybe_bool(&mut self, maybe_bool: bool) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_BOOL, maybe_bool); } + #[inline] pub fn add_default_bool(&mut self, default_bool: bool) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_BOOL, default_bool, true); } + #[inline] pub fn add_just_enum(&mut self, just_enum: OptionalByte) { self.fbb_.push_slot::(ScalarStuff::VT_JUST_ENUM, just_enum, OptionalByte::None); } + #[inline] pub fn add_maybe_enum(&mut self, maybe_enum: OptionalByte) { self.fbb_.push_slot_always::(ScalarStuff::VT_MAYBE_ENUM, maybe_enum); } + #[inline] pub fn add_default_enum(&mut self, default_enum: OptionalByte) { self.fbb_.push_slot::(ScalarStuff::VT_DEFAULT_ENUM, default_enum, OptionalByte::One); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> ScalarStuffBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -724,6 +801,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> ScalarStuffBuilder<'a, 'b, A> start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -773,6 +851,7 @@ impl ::core::fmt::Debug for ScalarStuff<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct ScalarStuffT { @@ -813,6 +892,7 @@ pub struct ScalarStuffT { pub maybe_enum: Option, pub default_enum: OptionalByte, } + impl Default for ScalarStuffT { fn default() -> Self { Self { @@ -855,6 +935,7 @@ impl Default for ScalarStuffT { } } } + impl ScalarStuffT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, @@ -936,66 +1017,73 @@ impl ScalarStuffT { }) } } -#[inline] + /// Verifies that a buffer of bytes contains a `ScalarStuff` /// and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_scalar_stuff_unchecked`. +#[inline] pub fn root_as_scalar_stuff(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::root::(buf) } -#[inline] + /// Verifies that a buffer of bytes contains a size prefixed /// `ScalarStuff` and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_scalar_stuff_unchecked`. +#[inline] pub fn size_prefixed_root_as_scalar_stuff(buf: &[u8]) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::size_prefixed_root::(buf) } -#[inline] + /// Verifies, with the given options, that a buffer of bytes /// contains a `ScalarStuff` and returns it. /// Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_scalar_stuff_unchecked`. +#[inline] pub fn root_as_scalar_stuff_with_opts<'b, 'o>( opts: &'o ::flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::root_with_opts::>(opts, buf) } -#[inline] + /// Verifies, with the given verifier options, that a buffer of /// bytes contains a size prefixed `ScalarStuff` and returns /// it. Note that verification is still experimental and may not /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `root_as_scalar_stuff_unchecked`. +#[inline] pub fn size_prefixed_root_as_scalar_stuff_with_opts<'b, 'o>( opts: &'o ::flatbuffers::VerifierOptions, buf: &'b [u8], ) -> Result, ::flatbuffers::InvalidFlatbuffer> { ::flatbuffers::size_prefixed_root_with_opts::>(opts, buf) } -#[inline] + /// Assumes, without verification, that a buffer of bytes contains a ScalarStuff and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid `ScalarStuff`. +#[inline] pub unsafe fn root_as_scalar_stuff_unchecked(buf: &[u8]) -> ScalarStuff<'_> { unsafe { ::flatbuffers::root_unchecked::(buf) } } -#[inline] + /// Assumes, without verification, that a buffer of bytes contains a size prefixed ScalarStuff and returns it. /// # Safety /// Callers must trust the given bytes do indeed contain a valid size prefixed `ScalarStuff`. +#[inline] pub unsafe fn size_prefixed_root_as_scalar_stuff_unchecked(buf: &[u8]) -> ScalarStuff<'_> { unsafe { ::flatbuffers::size_prefixed_root_unchecked::(buf) } } + pub const SCALAR_STUFF_IDENTIFIER: &str = "NULL"; #[inline] diff --git a/tests/private_annotation_test/ab_generated.rs b/tests/private_annotation_test/ab_generated.rs index c8fd77cc07f..91310b1db82 100644 --- a/tests/private_annotation_test/ab_generated.rs +++ b/tests/private_annotation_test/ab_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_AB: i8 = 1; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_AB: [AB; 2] = [ @@ -16,6 +19,7 @@ pub const ENUM_VALUES_AB: [AB; 2] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub(crate) struct AB(pub i8); + #[allow(non_upper_case_globals)] impl AB { pub const A: Self = Self(0); @@ -27,6 +31,7 @@ impl AB { Self::A, Self::B, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -36,6 +41,7 @@ impl AB { } } } + impl ::core::fmt::Debug for AB { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -45,8 +51,10 @@ impl ::core::fmt::Debug for AB { } } } + impl<'a> ::flatbuffers::Follow<'a> for AB { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -56,6 +64,7 @@ impl<'a> ::flatbuffers::Follow<'a> for AB { impl ::flatbuffers::Push for AB { type Output = AB; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -64,10 +73,12 @@ impl ::flatbuffers::Push for AB { impl ::flatbuffers::EndianScalar for AB { type Scalar = i8; + #[inline] fn to_little_endian(self) -> i8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: i8) -> Self { diff --git a/tests/private_annotation_test/annotations_generated.rs b/tests/private_annotation_test/annotations_generated.rs index 3db01a9fbc2..ab2039392b0 100644 --- a/tests/private_annotation_test/annotations_generated.rs +++ b/tests/private_annotation_test/annotations_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub(crate) enum AnnotationsOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub(crate) struct Annotations<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Annotations<'a> { type Inner = Annotations<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> Annotations<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Annotations { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -65,9 +68,11 @@ impl ::flatbuffers::Verifiable for Annotations<'_> { Ok(()) } } + pub(crate) struct AnnotationsArgs { pub value: i32, } + impl<'a> Default for AnnotationsArgs { #[inline] fn default() -> Self { @@ -81,11 +86,13 @@ pub(crate) struct AnnotationsBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + ' fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> AnnotationsBuilder<'a, 'b, A> { #[inline] pub fn add_value(&mut self, value: i32) { self.fbb_.push_slot::(Annotations::VT_VALUE, value, 0); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> AnnotationsBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -94,6 +101,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> AnnotationsBuilder<'a, 'b, A> start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -108,11 +116,13 @@ impl ::core::fmt::Debug for Annotations<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub(crate) struct AnnotationsT { pub value: i32, } + impl Default for AnnotationsT { fn default() -> Self { Self { @@ -120,6 +130,7 @@ impl Default for AnnotationsT { } } } + impl AnnotationsT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, diff --git a/tests/private_annotation_test/any_generated.rs b/tests/private_annotation_test/any_generated.rs index dd6aed8a275..be353bf47ca 100644 --- a/tests/private_annotation_test/any_generated.rs +++ b/tests/private_annotation_test/any_generated.rs @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ANY: u8 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ANY: [Any; 3] = [ @@ -17,6 +20,7 @@ pub const ENUM_VALUES_ANY: [Any; 3] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub(crate) struct Any(pub u8); + #[allow(non_upper_case_globals)] impl Any { pub const NONE: Self = Self(0); @@ -30,6 +34,7 @@ impl Any { Self::Game, Self::Annotations, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -40,6 +45,7 @@ impl Any { } } } + impl ::core::fmt::Debug for Any { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -49,8 +55,10 @@ impl ::core::fmt::Debug for Any { } } } + impl<'a> ::flatbuffers::Follow<'a> for Any { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -60,6 +68,7 @@ impl<'a> ::flatbuffers::Follow<'a> for Any { impl ::flatbuffers::Push for Any { type Output = Any; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -68,10 +77,12 @@ impl ::flatbuffers::Push for Any { impl ::flatbuffers::EndianScalar for Any { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -90,6 +101,7 @@ impl<'a> ::flatbuffers::Verifiable for Any { } impl ::flatbuffers::SimpleToVerifyInSlice for Any {} + pub(crate) struct AnyUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -100,11 +112,13 @@ pub(crate) enum AnyT { Game(alloc::boxed::Box), Annotations(alloc::boxed::Box), } + impl Default for AnyT { fn default() -> Self { Self::NONE } } + impl AnyT { pub fn any_type(&self) -> Any { match self { @@ -113,6 +127,7 @@ impl AnyT { Self::Annotations(_) => Any::Annotations, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, @@ -120,6 +135,7 @@ impl AnyT { Self::Annotations(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned GameT, setting the union to NONE. pub fn take_game(&mut self) -> Option> { if let Self::Game(_) = self { @@ -133,14 +149,17 @@ impl AnyT { None } } + /// If the union variant matches, return a reference to the GameT. pub fn as_game(&self) -> Option<&GameT> { if let Self::Game(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the GameT. pub fn as_game_mut(&mut self) -> Option<&mut GameT> { 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> { if let Self::Annotations(_) = self { @@ -154,12 +173,15 @@ impl AnyT { None } } + /// If the union variant matches, return a reference to the AnnotationsT. pub fn as_annotations(&self) -> Option<&AnnotationsT> { if let Self::Annotations(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the AnnotationsT. pub fn as_annotations_mut(&mut self) -> Option<&mut AnnotationsT> { if let Self::Annotations(v) = self { Some(v.as_mut()) } else { None } } } + diff --git a/tests/private_annotation_test/game_generated.rs b/tests/private_annotation_test/game_generated.rs index b43ce1885c9..7fa953b0c98 100644 --- a/tests/private_annotation_test/game_generated.rs +++ b/tests/private_annotation_test/game_generated.rs @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub(crate) enum GameOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub(crate) struct Game<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for Game<'a> { type Inner = Game<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -28,6 +30,7 @@ impl<'a> Game<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { Game { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -65,9 +68,11 @@ impl ::flatbuffers::Verifiable for Game<'_> { Ok(()) } } + pub(crate) struct GameArgs { pub value: i32, } + impl<'a> Default for GameArgs { #[inline] fn default() -> Self { @@ -81,11 +86,13 @@ pub(crate) struct GameBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> GameBuilder<'a, 'b, A> { #[inline] pub fn add_value(&mut self, value: i32) { self.fbb_.push_slot::(Game::VT_VALUE, value, 0); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> GameBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -94,6 +101,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> GameBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -108,11 +116,13 @@ impl ::core::fmt::Debug for Game<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub(crate) struct GameT { pub value: i32, } + impl Default for GameT { fn default() -> Self { Self { @@ -120,6 +130,7 @@ impl Default for GameT { } } } + impl GameT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, diff --git a/tests/private_annotation_test/object_generated.rs b/tests/private_annotation_test/object_generated.rs index 5e98d992705..3d5106ddbcd 100644 --- a/tests/private_annotation_test/object_generated.rs +++ b/tests/private_annotation_test/object_generated.rs @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct Object, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub(crate) struct Object(pub [u8; 4]); + impl Default for Object { fn default() -> Self { Self([0; 4]) } } + impl ::core::fmt::Debug for Object { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("Object") @@ -20,27 +23,34 @@ impl ::core::fmt::Debug for Object { } impl ::flatbuffers::SimpleToVerifyInSlice for Object {} + impl<'a> ::flatbuffers::Follow<'a> for Object { type Inner = &'a Object; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a Object>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a Object { type Inner = &'a Object; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for Object { type Output = Object; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const Object as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -110,6 +120,7 @@ impl<'a> Object { pub(crate) struct ObjectT { pub value: i32, } + impl ObjectT { pub fn pack(&self) -> Object { Object::new( @@ -117,4 +128,3 @@ impl ObjectT { ) } } - 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..88e0da134c8 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum FieldTableOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct FieldTable<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for FieldTable<'a> { type Inner = FieldTable<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -18,7 +20,6 @@ impl<'a> ::flatbuffers::Follow<'a> for FieldTable<'a> { } impl<'a> FieldTable<'a> { - pub const fn get_fully_qualified_name() -> &'static str { "RustNamerTest.FieldTable" } @@ -27,6 +28,7 @@ impl<'a> FieldTable<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { FieldTable { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -52,8 +54,10 @@ impl ::flatbuffers::Verifiable for FieldTable<'_> { Ok(()) } } + pub struct FieldTableArgs { } + impl<'a> Default for FieldTableArgs { #[inline] fn default() -> Self { @@ -66,6 +70,7 @@ pub struct FieldTableBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> FieldTableBuilder<'a, 'b, A> { #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> FieldTableBuilder<'a, 'b, A> { @@ -75,6 +80,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> FieldTableBuilder<'a, 'b, A> start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -88,16 +94,19 @@ impl ::core::fmt::Debug for FieldTable<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct FieldTableT { } + impl Default for FieldTableT { fn default() -> Self { Self { } } } + impl FieldTableT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..7bedafe0f0e 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 @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_FIELD_UNION: u8 = 1; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_FIELD_UNION: [FieldUnion; 2] = [ @@ -16,6 +19,7 @@ pub const ENUM_VALUES_FIELD_UNION: [FieldUnion; 2] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct FieldUnion(pub u8); + #[allow(non_upper_case_globals)] impl FieldUnion { pub const NONE: Self = Self(0); @@ -27,6 +31,7 @@ impl FieldUnion { Self::NONE, Self::f, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -36,6 +41,7 @@ impl FieldUnion { } } } + impl ::core::fmt::Debug for FieldUnion { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -45,8 +51,10 @@ impl ::core::fmt::Debug for FieldUnion { } } } + impl<'a> ::flatbuffers::Follow<'a> for FieldUnion { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -56,6 +64,7 @@ impl<'a> ::flatbuffers::Follow<'a> for FieldUnion { impl ::flatbuffers::Push for FieldUnion { type Output = FieldUnion; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -64,10 +73,12 @@ impl ::flatbuffers::Push for FieldUnion { impl ::flatbuffers::EndianScalar for FieldUnion { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -86,6 +97,7 @@ impl<'a> ::flatbuffers::Verifiable for FieldUnion { } impl ::flatbuffers::SimpleToVerifyInSlice for FieldUnion {} + pub struct FieldUnionUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -95,11 +107,13 @@ pub enum FieldUnionT { NONE, F(alloc::boxed::Box), } + impl Default for FieldUnionT { fn default() -> Self { Self::NONE } } + impl FieldUnionT { pub fn field_union_type(&self) -> FieldUnion { match self { @@ -107,12 +121,14 @@ impl FieldUnionT { Self::F(_) => FieldUnion::f, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, Self::F(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned FieldTableT, setting the union to NONE. pub fn take_f(&mut self) -> Option> { if let Self::F(_) = self { @@ -126,12 +142,15 @@ impl FieldUnionT { None } } + /// If the union variant matches, return a reference to the FieldTableT. pub fn as_f(&self) -> Option<&FieldTableT> { if let Self::F(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the FieldTableT. pub fn as_f_mut(&mut self) -> Option<&mut FieldTableT> { if let Self::F(v) = self { Some(v.as_mut()) } else { None } } } + 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..5d4dc481048 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 @@ -2,10 +2,13 @@ // @generated extern crate alloc; 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; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_GAME_MESSAGE: u8 = 3; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_GAME_MESSAGE: [GameMessage; 4] = [ @@ -18,6 +21,7 @@ pub const ENUM_VALUES_GAME_MESSAGE: [GameMessage; 4] = [ #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct GameMessage(pub u8); + #[allow(non_upper_case_globals)] impl GameMessage { pub const NONE: Self = Self(0); @@ -33,6 +37,7 @@ impl GameMessage { Self::PlayerSpectate, Self::PlayerInputChange, ]; + /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -44,6 +49,7 @@ impl GameMessage { } } } + impl ::core::fmt::Debug for GameMessage { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { if let Some(name) = self.variant_name() { @@ -53,8 +59,10 @@ impl ::core::fmt::Debug for GameMessage { } } } + impl<'a> ::flatbuffers::Follow<'a> for GameMessage { type Inner = Self; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { let b = unsafe { ::flatbuffers::read_scalar_at::(buf, loc) }; @@ -64,6 +72,7 @@ impl<'a> ::flatbuffers::Follow<'a> for GameMessage { impl ::flatbuffers::Push for GameMessage { type Output = GameMessage; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { unsafe { ::flatbuffers::emplace_scalar::(dst, self.0) }; @@ -72,10 +81,12 @@ impl ::flatbuffers::Push for GameMessage { impl ::flatbuffers::EndianScalar for GameMessage { type Scalar = u8; + #[inline] fn to_little_endian(self) -> u8 { self.0.to_le() } + #[inline] #[allow(clippy::wrong_self_convention)] fn from_little_endian(v: u8) -> Self { @@ -94,6 +105,7 @@ impl<'a> ::flatbuffers::Verifiable for GameMessage { } impl ::flatbuffers::SimpleToVerifyInSlice for GameMessage {} + pub struct GameMessageUnionTableOffset {} #[allow(clippy::upper_case_acronyms)] @@ -105,11 +117,13 @@ pub enum GameMessageT { PlayerSpectate(alloc::boxed::Box), PlayerInputChange(alloc::boxed::Box), } + impl Default for GameMessageT { fn default() -> Self { Self::NONE } } + impl GameMessageT { pub fn game_message_type(&self) -> GameMessage { match self { @@ -119,6 +133,7 @@ impl GameMessageT { Self::PlayerInputChange(_) => GameMessage::PlayerInputChange, } } + pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> { match self { Self::NONE => None, @@ -127,6 +142,7 @@ impl GameMessageT { Self::PlayerInputChange(v) => Some(v.pack(fbb).as_union_value()), } } + /// If the union variant matches, return the owned PlayerStatEventT, setting the union to NONE. pub fn take_player_stat_event(&mut self) -> Option> { if let Self::PlayerStatEvent(_) = self { @@ -140,14 +156,17 @@ impl GameMessageT { None } } + /// If the union variant matches, return a reference to the PlayerStatEventT. pub fn as_player_stat_event(&self) -> Option<&PlayerStatEventT> { if let Self::PlayerStatEvent(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the PlayerStatEventT. pub fn as_player_stat_event_mut(&mut self) -> Option<&mut PlayerStatEventT> { 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> { if let Self::PlayerSpectate(_) = self { @@ -161,14 +180,17 @@ impl GameMessageT { None } } + /// If the union variant matches, return a reference to the PlayerSpectateT. pub fn as_player_spectate(&self) -> Option<&PlayerSpectateT> { if let Self::PlayerSpectate(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the PlayerSpectateT. pub fn as_player_spectate_mut(&mut self) -> Option<&mut PlayerSpectateT> { 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> { if let Self::PlayerInputChange(_) = self { @@ -182,12 +204,15 @@ impl GameMessageT { None } } + /// If the union variant matches, return a reference to the PlayerInputChangeT. pub fn as_player_input_change(&self) -> Option<&PlayerInputChangeT> { if let Self::PlayerInputChange(v) = self { Some(v.as_ref()) } else { None } } + /// If the union variant matches, return a mutable reference to the PlayerInputChangeT. pub fn as_player_input_change_mut(&mut self) -> Option<&mut PlayerInputChangeT> { if let Self::PlayerInputChange(v) = self { Some(v.as_mut()) } else { None } } } + 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..6132c77e3cc 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum GameMessageWrapperOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct GameMessageWrapper<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for GameMessageWrapper<'a> { type Inner = GameMessageWrapper<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -29,6 +31,7 @@ impl<'a> GameMessageWrapper<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { GameMessageWrapper { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -72,6 +75,7 @@ impl<'a> GameMessageWrapper<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(GameMessageWrapper::VT_MESSAGE_TYPE, Some(GameMessage::NONE)).unwrap()} } + #[inline] pub fn Message(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -79,6 +83,7 @@ impl<'a> GameMessageWrapper<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(GameMessageWrapper::VT_MESSAGE, None)} } + #[inline] #[allow(non_snake_case)] pub fn Message_as_player_stat_event(&self) -> Option> { @@ -123,7 +128,6 @@ impl<'a> GameMessageWrapper<'a> { None } } - } impl ::flatbuffers::Verifiable for GameMessageWrapper<'_> { @@ -144,10 +148,12 @@ impl ::flatbuffers::Verifiable for GameMessageWrapper<'_> { Ok(()) } } + pub struct GameMessageWrapperArgs { pub Message_type: GameMessage, pub Message: Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>>, } + impl<'a> Default for GameMessageWrapperArgs { #[inline] fn default() -> Self { @@ -162,15 +168,18 @@ pub struct GameMessageWrapperBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + ' fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> GameMessageWrapperBuilder<'a, 'b, A> { #[inline] pub fn add_Message_type(&mut self, Message_type: GameMessage) { self.fbb_.push_slot::(GameMessageWrapper::VT_MESSAGE_TYPE, Message_type, GameMessage::NONE); } + #[inline] pub fn add_Message(&mut self, Message: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(GameMessageWrapper::VT_MESSAGE, Message); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> GameMessageWrapperBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -179,6 +188,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> GameMessageWrapperBuilder<'a, start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -220,11 +230,13 @@ impl ::core::fmt::Debug for GameMessageWrapper<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct GameMessageWrapperT { pub Message: GameMessageT, } + impl Default for GameMessageWrapperT { fn default() -> Self { Self { @@ -232,6 +244,7 @@ impl Default for GameMessageWrapperT { } } } + impl GameMessageWrapperT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..75fb6e4f63f 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum PlayerInputChangeOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct PlayerInputChange<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for PlayerInputChange<'a> { type Inner = PlayerInputChange<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -18,7 +20,6 @@ impl<'a> ::flatbuffers::Follow<'a> for PlayerInputChange<'a> { } impl<'a> PlayerInputChange<'a> { - pub const fn get_fully_qualified_name() -> &'static str { "RustNamerTest.PlayerInputChange" } @@ -27,6 +28,7 @@ impl<'a> PlayerInputChange<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { PlayerInputChange { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -52,8 +54,10 @@ impl ::flatbuffers::Verifiable for PlayerInputChange<'_> { Ok(()) } } + pub struct PlayerInputChangeArgs { } + impl<'a> Default for PlayerInputChangeArgs { #[inline] fn default() -> Self { @@ -66,6 +70,7 @@ pub struct PlayerInputChangeBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> PlayerInputChangeBuilder<'a, 'b, A> { #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> PlayerInputChangeBuilder<'a, 'b, A> { @@ -75,6 +80,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> PlayerInputChangeBuilder<'a, start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -88,16 +94,19 @@ impl ::core::fmt::Debug for PlayerInputChange<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct PlayerInputChangeT { } + impl Default for PlayerInputChangeT { fn default() -> Self { Self { } } } + impl PlayerInputChangeT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..df9fbd9be83 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum PlayerSpectateOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct PlayerSpectate<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for PlayerSpectate<'a> { type Inner = PlayerSpectate<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -18,7 +20,6 @@ impl<'a> ::flatbuffers::Follow<'a> for PlayerSpectate<'a> { } impl<'a> PlayerSpectate<'a> { - pub const fn get_fully_qualified_name() -> &'static str { "RustNamerTest.PlayerSpectate" } @@ -27,6 +28,7 @@ impl<'a> PlayerSpectate<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { PlayerSpectate { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -52,8 +54,10 @@ impl ::flatbuffers::Verifiable for PlayerSpectate<'_> { Ok(()) } } + pub struct PlayerSpectateArgs { } + impl<'a> Default for PlayerSpectateArgs { #[inline] fn default() -> Self { @@ -66,6 +70,7 @@ pub struct PlayerSpectateBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> PlayerSpectateBuilder<'a, 'b, A> { #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> PlayerSpectateBuilder<'a, 'b, A> { @@ -75,6 +80,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> PlayerSpectateBuilder<'a, 'b, start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -88,16 +94,19 @@ impl ::core::fmt::Debug for PlayerSpectate<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct PlayerSpectateT { } + impl Default for PlayerSpectateT { fn default() -> Self { Self { } } } + impl PlayerSpectateT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..4ed80f0afa9 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum PlayerStatEventOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct PlayerStatEvent<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for PlayerStatEvent<'a> { type Inner = PlayerStatEvent<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -18,7 +20,6 @@ impl<'a> ::flatbuffers::Follow<'a> for PlayerStatEvent<'a> { } impl<'a> PlayerStatEvent<'a> { - pub const fn get_fully_qualified_name() -> &'static str { "RustNamerTest.PlayerStatEvent" } @@ -27,6 +28,7 @@ impl<'a> PlayerStatEvent<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { PlayerStatEvent { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -52,8 +54,10 @@ impl ::flatbuffers::Verifiable for PlayerStatEvent<'_> { Ok(()) } } + pub struct PlayerStatEventArgs { } + impl<'a> Default for PlayerStatEventArgs { #[inline] fn default() -> Self { @@ -66,6 +70,7 @@ pub struct PlayerStatEventBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> PlayerStatEventBuilder<'a, 'b, A> { #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> PlayerStatEventBuilder<'a, 'b, A> { @@ -75,6 +80,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> PlayerStatEventBuilder<'a, 'b start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -88,16 +94,19 @@ impl ::core::fmt::Debug for PlayerStatEvent<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct PlayerStatEventT { } + impl Default for PlayerStatEventT { fn default() -> Self { Self { } } } + impl PlayerStatEventT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self, 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..bff14ad2c8b 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 @@ -2,15 +2,18 @@ // @generated extern crate alloc; use super::*; + // struct PossiblyReservedWords, aligned to 4 #[repr(transparent)] #[derive(Clone, Copy, PartialEq)] pub struct PossiblyReservedWords(pub [u8; 16]); + impl Default for PossiblyReservedWords { fn default() -> Self { Self([0; 16]) } } + impl ::core::fmt::Debug for PossiblyReservedWords { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { f.debug_struct("PossiblyReservedWords") @@ -23,27 +26,34 @@ impl ::core::fmt::Debug for PossiblyReservedWords { } impl ::flatbuffers::SimpleToVerifyInSlice for PossiblyReservedWords {} + impl<'a> ::flatbuffers::Follow<'a> for PossiblyReservedWords { type Inner = &'a PossiblyReservedWords; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { <&'a PossiblyReservedWords>::follow(buf, loc) } } } + impl<'a> ::flatbuffers::Follow<'a> for &'a PossiblyReservedWords { type Inner = &'a PossiblyReservedWords; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { unsafe { ::flatbuffers::follow_cast_ref::(buf, loc) } } } + impl<'b> ::flatbuffers::Push for PossiblyReservedWords { type Output = PossiblyReservedWords; + #[inline] unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { let src = unsafe { ::core::slice::from_raw_parts(self as *const PossiblyReservedWords as *const u8, ::size()) }; dst.copy_from_slice(src); } + #[inline] fn alignment() -> ::flatbuffers::PushAlignment { ::flatbuffers::PushAlignment::new(4) @@ -212,6 +222,7 @@ pub struct PossiblyReservedWordsT { pub size: f32, pub alignment: f32, } + impl PossiblyReservedWordsT { pub fn pack(&self) -> PossiblyReservedWords { PossiblyReservedWords::new( @@ -222,4 +233,3 @@ impl PossiblyReservedWordsT { ) } } - 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..7677de09213 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 @@ -2,15 +2,17 @@ // @generated extern crate alloc; use super::*; + pub enum RootTableOffset {} -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub struct RootTable<'a> { pub _tab: ::flatbuffers::Table<'a>, } impl<'a> ::flatbuffers::Follow<'a> for RootTable<'a> { type Inner = RootTable<'a>; + #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } } @@ -29,6 +31,7 @@ impl<'a> RootTable<'a> { pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self { RootTable { _tab: table } } + #[allow(unused_mut)] pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>, @@ -62,6 +65,7 @@ impl<'a> RootTable<'a> { // which contains a valid value in this slot unsafe { self._tab.get::(RootTable::VT_FIELD42_TYPE, Some(FieldUnion::NONE)).unwrap()} } + #[inline] pub fn field42(&self) -> Option<::flatbuffers::Table<'a>> { // Safety: @@ -69,6 +73,7 @@ impl<'a> RootTable<'a> { // which contains a valid value in this slot unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Table<'a>>>(RootTable::VT_FIELD42, None)} } + #[inline] #[allow(non_snake_case)] pub fn field42_as_f(&self) -> Option> { @@ -83,7 +88,6 @@ impl<'a> RootTable<'a> { None } } - } impl ::flatbuffers::Verifiable for RootTable<'_> { @@ -102,10 +106,12 @@ impl ::flatbuffers::Verifiable for RootTable<'_> { Ok(()) } } + pub struct RootTableArgs { pub field42_type: FieldUnion, pub field42: Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>>, } + impl<'a> Default for RootTableArgs { #[inline] fn default() -> Self { @@ -120,15 +126,18 @@ pub struct RootTableBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> { fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>, start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>, } + impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> RootTableBuilder<'a, 'b, A> { #[inline] pub fn add_field42_type(&mut self, field42_type: FieldUnion) { self.fbb_.push_slot::(RootTable::VT_FIELD42_TYPE, field42_type, FieldUnion::NONE); } + #[inline] pub fn add_field42(&mut self, field42: ::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>) { self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(RootTable::VT_FIELD42, field42); } + #[inline] pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> RootTableBuilder<'a, 'b, A> { let start = _fbb.start_table(); @@ -137,6 +146,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> RootTableBuilder<'a, 'b, A> { start_: start, } } + #[inline] pub fn finish(self) -> ::flatbuffers::WIPOffset> { let o = self.fbb_.end_table(self.start_); @@ -164,11 +174,13 @@ impl ::core::fmt::Debug for RootTable<'_> { ds.finish() } } + #[non_exhaustive] #[derive(Debug, Clone, PartialEq)] pub struct RootTableT { pub field42: FieldUnionT, } + impl Default for RootTableT { fn default() -> Self { Self { @@ -176,6 +188,7 @@ impl Default for RootTableT { } } } + impl RootTableT { pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>( &self,