Rust codegen improvements and lint fixes (#6046)

* Improve rust codegen

* one more unneeded lifetime

* Added a derive default

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2020-07-25 13:46:20 -07:00
committed by GitHub
parent d76e93f277
commit 18b015d25a
8 changed files with 121 additions and 147 deletions

View File

@@ -41,7 +41,7 @@ pub fn lifted_follow<'a, T: Follow<'a>>(buf: &'a [u8], loc: usize) -> T::Inner {
/// FollowStart wraps a Follow impl in a struct type. This can make certain /// FollowStart wraps a Follow impl in a struct type. This can make certain
/// programming patterns more ergonomic. /// programming patterns more ergonomic.
#[derive(Debug)] #[derive(Debug, Default)]
pub struct FollowStart<T>(PhantomData<T>); pub struct FollowStart<T>(PhantomData<T>);
impl<'a, T: Follow<'a> + 'a> FollowStart<T> { impl<'a, T: Follow<'a> + 'a> FollowStart<T> {
#[inline] #[inline]

View File

@@ -616,7 +616,7 @@ class RustGenerator : public BaseGenerator {
static const uint64_t kMaxSparseness = 5; static const uint64_t kMaxSparseness = 5;
if (range / static_cast<uint64_t>(enum_def.size()) < kMaxSparseness) { if (range / static_cast<uint64_t>(enum_def.size()) < kMaxSparseness) {
code_ += "#[allow(non_camel_case_types)]"; code_ += "#[allow(non_camel_case_types)]";
code_ += "pub const ENUM_NAMES_{{ENUM_NAME_CAPS}}:[&'static str; " + code_ += "pub const ENUM_NAMES_{{ENUM_NAME_CAPS}}: [&str; " +
NumToString(range + 1) + "] = ["; NumToString(range + 1) + "] = [";
auto val = enum_def.Vals().front(); auto val = enum_def.Vals().front();
@@ -736,7 +736,6 @@ class RustGenerator : public BaseGenerator {
const auto typname = GetTypeBasic(type.VectorType()); const auto typname = GetTypeBasic(type.VectorType());
return "Option<flatbuffers::WIPOffset<flatbuffers::Vector<" + lifetime + return "Option<flatbuffers::WIPOffset<flatbuffers::Vector<" + lifetime +
", " + typname + ">>>"; ", " + typname + ">>>";
// TODO(cneo): Fix whitespace in generated code.
} }
case ftVectorOfEnumKey: { case ftVectorOfEnumKey: {
const auto typname = WrapInNameSpace(*type.enum_def); const auto typname = WrapInNameSpace(*type.enum_def);
@@ -832,7 +831,7 @@ class RustGenerator : public BaseGenerator {
} }
case ftStruct: { case ftStruct: {
const auto typname = WrapInNameSpace(*type.struct_def); const auto typname = WrapInNameSpace(*type.struct_def);
return "&" + lifetime + " " + typname + ""; return "&" + typname + "";
} }
case ftTable: { case ftTable: {
const auto typname = WrapInNameSpace(*type.struct_def); const auto typname = WrapInNameSpace(*type.struct_def);
@@ -1137,9 +1136,7 @@ class RustGenerator : public BaseGenerator {
code_ += " type Inner = {{STRUCT_NAME}}<'a>;"; code_ += " type Inner = {{STRUCT_NAME}}<'a>;";
code_ += " #[inline]"; code_ += " #[inline]";
code_ += " fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {"; code_ += " fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
code_ += " Self {"; code_ += " Self { _tab: flatbuffers::Table { buf, loc } }";
code_ += " _tab: flatbuffers::Table { buf: buf, loc: loc },";
code_ += " }";
code_ += " }"; code_ += " }";
code_ += "}"; code_ += "}";
code_ += ""; code_ += "";
@@ -1335,8 +1332,8 @@ class RustGenerator : public BaseGenerator {
code_ += " Some({{U_ELEMENT_TABLE_TYPE}}::init_from_table(u))"; code_ += " Some({{U_ELEMENT_TABLE_TYPE}}::init_from_table(u))";
} else { } else {
code_ += code_ +=
" self.{{FIELD_NAME}}().map(|u| " " self.{{FIELD_NAME}}().map("
"{{U_ELEMENT_TABLE_TYPE}}::init_from_table(u))"; "{{U_ELEMENT_TABLE_TYPE}}::init_from_table)";
} }
code_ += " } else {"; code_ += " } else {";
code_ += " None"; code_ += " None";
@@ -1523,7 +1520,8 @@ class RustGenerator : public BaseGenerator {
if (parser_.file_identifier_.length()) { if (parser_.file_identifier_.length()) {
// Declare the identifier // Declare the identifier
code_ += "pub const {{STRUCT_NAME_CAPS}}_IDENTIFIER: &'static str\\"; // (no lifetime needed as constants have static lifetimes by default)
code_ += "pub const {{STRUCT_NAME_CAPS}}_IDENTIFIER: &str\\";
code_ += " = \"" + parser_.file_identifier_ + "\";"; code_ += " = \"" + parser_.file_identifier_ + "\";";
code_ += ""; code_ += "";
@@ -1531,22 +1529,22 @@ class RustGenerator : public BaseGenerator {
code_ += "#[inline]"; code_ += "#[inline]";
code_ += "pub fn {{STRUCT_NAME_SNAKECASE}}_buffer_has_identifier\\"; code_ += "pub fn {{STRUCT_NAME_SNAKECASE}}_buffer_has_identifier\\";
code_ += "(buf: &[u8]) -> bool {"; code_ += "(buf: &[u8]) -> bool {";
code_ += " return flatbuffers::buffer_has_identifier(buf, \\"; code_ += " flatbuffers::buffer_has_identifier(buf, \\";
code_ += "{{STRUCT_NAME_CAPS}}_IDENTIFIER, false);"; code_ += "{{STRUCT_NAME_CAPS}}_IDENTIFIER, false)";
code_ += "}"; code_ += "}";
code_ += ""; code_ += "";
code_ += "#[inline]"; code_ += "#[inline]";
code_ += "pub fn {{STRUCT_NAME_SNAKECASE}}_size_prefixed\\"; code_ += "pub fn {{STRUCT_NAME_SNAKECASE}}_size_prefixed\\";
code_ += "_buffer_has_identifier(buf: &[u8]) -> bool {"; code_ += "_buffer_has_identifier(buf: &[u8]) -> bool {";
code_ += " return flatbuffers::buffer_has_identifier(buf, \\"; code_ += " flatbuffers::buffer_has_identifier(buf, \\";
code_ += "{{STRUCT_NAME_CAPS}}_IDENTIFIER, true);"; code_ += "{{STRUCT_NAME_CAPS}}_IDENTIFIER, true)";
code_ += "}"; code_ += "}";
code_ += ""; code_ += "";
} }
if (parser_.file_extension_.length()) { if (parser_.file_extension_.length()) {
// Return the extension // Return the extension
code_ += "pub const {{STRUCT_NAME_CAPS}}_EXTENSION: &'static str = \\"; code_ += "pub const {{STRUCT_NAME_CAPS}}_EXTENSION: &str = \\";
code_ += "\"" + parser_.file_extension_ + "\";"; code_ += "\"" + parser_.file_extension_ + "\";";
code_ += ""; code_ += "";
} }
@@ -1694,7 +1692,7 @@ class RustGenerator : public BaseGenerator {
const auto &field = **it; const auto &field = **it;
const auto member_name = Name(field) + "_"; const auto member_name = Name(field) + "_";
const auto reference = const auto reference =
StructMemberAccessNeedsCopy(field.value.type) ? "" : "&'a "; StructMemberAccessNeedsCopy(field.value.type) ? "" : "&";
const auto arg_name = "_" + Name(field); const auto arg_name = "_" + Name(field);
const auto arg_type = reference + GetTypeGet(field.value.type); const auto arg_type = reference + GetTypeGet(field.value.type);
@@ -1711,7 +1709,7 @@ class RustGenerator : public BaseGenerator {
code_.SetValue("ARG_LIST", arg_list); code_.SetValue("ARG_LIST", arg_list);
code_.SetValue("INIT_LIST", init_list); code_.SetValue("INIT_LIST", init_list);
code_ += " pub fn new<'a>({{ARG_LIST}}) -> Self {"; code_ += " pub fn new({{ARG_LIST}}) -> Self {";
code_ += " {{STRUCT_NAME}} {"; code_ += " {{STRUCT_NAME}} {";
code_ += "{{INIT_LIST}}"; code_ += "{{INIT_LIST}}";
padding_id = 0; padding_id = 0;
@@ -1745,12 +1743,16 @@ class RustGenerator : public BaseGenerator {
code_.SetValue("FIELD_NAME", Name(field)); code_.SetValue("FIELD_NAME", Name(field));
code_.SetValue("FIELD_TYPE", field_type); code_.SetValue("FIELD_TYPE", field_type);
code_.SetValue("FIELD_VALUE", value); code_.SetValue("FIELD_VALUE", value);
code_.SetValue("REF", IsStruct(field.value.type) ? "&" : "");
GenComment(field.doc_comment, " "); GenComment(field.doc_comment, " ");
code_ += " pub fn {{FIELD_NAME}}<'a>(&'a self) -> {{FIELD_TYPE}} {"; if (IsStruct(field.value.type)) {
code_ += " {{REF}}{{FIELD_VALUE}}"; code_ += " pub fn {{FIELD_NAME}}(&self) -> {{FIELD_TYPE}} {";
code_ += " &{{FIELD_VALUE}}";
code_ += " }"; code_ += " }";
} else {
code_ += " pub fn {{FIELD_NAME}}(&self) -> {{FIELD_TYPE}} {";
code_ += " {{FIELD_VALUE}}";
code_ += " }";
}
// Generate a comparison function for this field if it is a key. // Generate a comparison function for this field if it is a key.
if (field.key) { GenKeyFieldMethods(field); } if (field.key) { GenKeyFieldMethods(field); }

View File

@@ -20,9 +20,7 @@ impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
type Inner = TableA<'a>; type Inner = TableA<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }

View File

@@ -76,7 +76,7 @@ pub const ENUM_VALUES_FROM_INCLUDE:[FromInclude; 1] = [
]; ];
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub const ENUM_NAMES_FROM_INCLUDE:[&'static str; 1] = [ pub const ENUM_NAMES_FROM_INCLUDE: [&str; 1] = [
"IncludeVal" "IncludeVal"
]; ];
@@ -130,13 +130,13 @@ impl<'b> flatbuffers::Push for &'b Unused {
impl Unused { impl Unused {
pub fn new<'a>(_a: i32) -> Self { pub fn new(_a: i32) -> Self {
Unused { Unused {
a_: _a.to_little_endian(), a_: _a.to_little_endian(),
} }
} }
pub fn a<'a>(&'a self) -> i32 { pub fn a(&self) -> i32 {
self.a_.from_little_endian() self.a_.from_little_endian()
} }
} }
@@ -152,9 +152,7 @@ impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
type Inner = TableB<'a>; type Inner = TableB<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }

View File

@@ -32,9 +32,7 @@ impl<'a> flatbuffers::Follow<'a> for InParentNamespace<'a> {
type Inner = InParentNamespace<'a>; type Inner = InParentNamespace<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }
@@ -110,9 +108,7 @@ impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
type Inner = Monster<'a>; type Inner = Monster<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }
@@ -235,7 +231,7 @@ pub const ENUM_VALUES_COLOR:[Color; 3] = [
]; ];
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub const ENUM_NAMES_COLOR:[&'static str; 8] = [ pub const ENUM_NAMES_COLOR: [&str; 8] = [
"Red", "Red",
"Green", "Green",
"", "",
@@ -305,7 +301,7 @@ pub const ENUM_VALUES_RACE:[Race; 4] = [
]; ];
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub const ENUM_NAMES_RACE:[&'static str; 4] = [ pub const ENUM_NAMES_RACE: [&str; 4] = [
"None", "None",
"Human", "Human",
"Dwarf", "Dwarf",
@@ -371,7 +367,7 @@ pub const ENUM_VALUES_ANY:[Any; 4] = [
]; ];
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub const ENUM_NAMES_ANY:[&'static str; 4] = [ pub const ENUM_NAMES_ANY: [&str; 4] = [
"NONE", "NONE",
"Monster", "Monster",
"TestSimpleTableWithEnum", "TestSimpleTableWithEnum",
@@ -438,7 +434,7 @@ pub const ENUM_VALUES_ANY_UNIQUE_ALIASES:[AnyUniqueAliases; 4] = [
]; ];
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub const ENUM_NAMES_ANY_UNIQUE_ALIASES:[&'static str; 4] = [ pub const ENUM_NAMES_ANY_UNIQUE_ALIASES: [&str; 4] = [
"NONE", "NONE",
"M", "M",
"TS", "TS",
@@ -505,7 +501,7 @@ pub const ENUM_VALUES_ANY_AMBIGUOUS_ALIASES:[AnyAmbiguousAliases; 4] = [
]; ];
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub const ENUM_NAMES_ANY_AMBIGUOUS_ALIASES:[&'static str; 4] = [ pub const ENUM_NAMES_ANY_AMBIGUOUS_ALIASES: [&str; 4] = [
"NONE", "NONE",
"M1", "M1",
"M2", "M2",
@@ -565,7 +561,7 @@ impl<'b> flatbuffers::Push for &'b Test {
impl Test { impl Test {
pub fn new<'a>(_a: i16, _b: i8) -> Self { pub fn new(_a: i16, _b: i8) -> Self {
Test { Test {
a_: _a.to_little_endian(), a_: _a.to_little_endian(),
b_: _b.to_little_endian(), b_: _b.to_little_endian(),
@@ -577,10 +573,10 @@ impl Test {
"MyGame.Example.Test" "MyGame.Example.Test"
} }
pub fn a<'a>(&'a self) -> i16 { pub fn a(&self) -> i16 {
self.a_.from_little_endian() self.a_.from_little_endian()
} }
pub fn b<'a>(&'a self) -> i8 { pub fn b(&self) -> i8 {
self.b_.from_little_endian() self.b_.from_little_endian()
} }
} }
@@ -638,7 +634,7 @@ impl<'b> flatbuffers::Push for &'b Vec3 {
impl Vec3 { impl Vec3 {
pub fn new<'a>(_x: f32, _y: f32, _z: f32, _test1: f64, _test2: Color, _test3: &'a Test) -> Self { pub fn new(_x: f32, _y: f32, _z: f32, _test1: f64, _test2: Color, _test3: &Test) -> Self {
Vec3 { Vec3 {
x_: _x.to_little_endian(), x_: _x.to_little_endian(),
y_: _y.to_little_endian(), y_: _y.to_little_endian(),
@@ -656,22 +652,22 @@ impl Vec3 {
"MyGame.Example.Vec3" "MyGame.Example.Vec3"
} }
pub fn x<'a>(&'a self) -> f32 { pub fn x(&self) -> f32 {
self.x_.from_little_endian() self.x_.from_little_endian()
} }
pub fn y<'a>(&'a self) -> f32 { pub fn y(&self) -> f32 {
self.y_.from_little_endian() self.y_.from_little_endian()
} }
pub fn z<'a>(&'a self) -> f32 { pub fn z(&self) -> f32 {
self.z_.from_little_endian() self.z_.from_little_endian()
} }
pub fn test1<'a>(&'a self) -> f64 { pub fn test1(&self) -> f64 {
self.test1_.from_little_endian() self.test1_.from_little_endian()
} }
pub fn test2<'a>(&'a self) -> Color { pub fn test2(&self) -> Color {
self.test2_.from_little_endian() self.test2_.from_little_endian()
} }
pub fn test3<'a>(&'a self) -> &'a Test { pub fn test3(&self) -> &Test {
&self.test3_ &self.test3_
} }
} }
@@ -722,7 +718,7 @@ impl<'b> flatbuffers::Push for &'b Ability {
impl Ability { impl Ability {
pub fn new<'a>(_id: u32, _distance: u32) -> Self { pub fn new(_id: u32, _distance: u32) -> Self {
Ability { Ability {
id_: _id.to_little_endian(), id_: _id.to_little_endian(),
distance_: _distance.to_little_endian(), distance_: _distance.to_little_endian(),
@@ -733,7 +729,7 @@ impl Ability {
"MyGame.Example.Ability" "MyGame.Example.Ability"
} }
pub fn id<'a>(&'a self) -> u32 { pub fn id(&self) -> u32 {
self.id_.from_little_endian() self.id_.from_little_endian()
} }
#[inline] #[inline]
@@ -746,7 +742,7 @@ impl Ability {
let key = self.id(); let key = self.id();
key.cmp(&val) key.cmp(&val)
} }
pub fn distance<'a>(&'a self) -> u32 { pub fn distance(&self) -> u32 {
self.distance_.from_little_endian() self.distance_.from_little_endian()
} }
} }
@@ -762,9 +758,7 @@ impl<'a> flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> {
type Inner = TestSimpleTableWithEnum<'a>; type Inner = TestSimpleTableWithEnum<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }
@@ -842,9 +836,7 @@ impl<'a> flatbuffers::Follow<'a> for Stat<'a> {
type Inner = Stat<'a>; type Inner = Stat<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }
@@ -946,9 +938,7 @@ impl<'a> flatbuffers::Follow<'a> for Referrable<'a> {
type Inner = Referrable<'a>; type Inner = Referrable<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }
@@ -1037,9 +1027,7 @@ impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
type Inner = Monster<'a>; type Inner = Monster<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }
@@ -1376,7 +1364,7 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn test_as_monster(&self) -> Option<Monster<'a>> { pub fn test_as_monster(&self) -> Option<Monster<'a>> {
if self.test_type() == Any::Monster { if self.test_type() == Any::Monster {
self.test().map(|u| Monster::init_from_table(u)) self.test().map(Monster::init_from_table)
} else { } else {
None None
} }
@@ -1386,7 +1374,7 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn test_as_test_simple_table_with_enum(&self) -> Option<TestSimpleTableWithEnum<'a>> { pub fn test_as_test_simple_table_with_enum(&self) -> Option<TestSimpleTableWithEnum<'a>> {
if self.test_type() == Any::TestSimpleTableWithEnum { if self.test_type() == Any::TestSimpleTableWithEnum {
self.test().map(|u| TestSimpleTableWithEnum::init_from_table(u)) self.test().map(TestSimpleTableWithEnum::init_from_table)
} else { } else {
None None
} }
@@ -1396,7 +1384,7 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn test_as_my_game_example_2_monster(&self) -> Option<super::example_2::Monster<'a>> { pub fn test_as_my_game_example_2_monster(&self) -> Option<super::example_2::Monster<'a>> {
if self.test_type() == Any::MyGame_Example2_Monster { if self.test_type() == Any::MyGame_Example2_Monster {
self.test().map(|u| super::example_2::Monster::init_from_table(u)) self.test().map(super::example_2::Monster::init_from_table)
} else { } else {
None None
} }
@@ -1406,7 +1394,7 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn any_unique_as_m(&self) -> Option<Monster<'a>> { pub fn any_unique_as_m(&self) -> Option<Monster<'a>> {
if self.any_unique_type() == AnyUniqueAliases::M { if self.any_unique_type() == AnyUniqueAliases::M {
self.any_unique().map(|u| Monster::init_from_table(u)) self.any_unique().map(Monster::init_from_table)
} else { } else {
None None
} }
@@ -1416,7 +1404,7 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn any_unique_as_ts(&self) -> Option<TestSimpleTableWithEnum<'a>> { pub fn any_unique_as_ts(&self) -> Option<TestSimpleTableWithEnum<'a>> {
if self.any_unique_type() == AnyUniqueAliases::TS { if self.any_unique_type() == AnyUniqueAliases::TS {
self.any_unique().map(|u| TestSimpleTableWithEnum::init_from_table(u)) self.any_unique().map(TestSimpleTableWithEnum::init_from_table)
} else { } else {
None None
} }
@@ -1426,7 +1414,7 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn any_unique_as_m2(&self) -> Option<super::example_2::Monster<'a>> { pub fn any_unique_as_m2(&self) -> Option<super::example_2::Monster<'a>> {
if self.any_unique_type() == AnyUniqueAliases::M2 { if self.any_unique_type() == AnyUniqueAliases::M2 {
self.any_unique().map(|u| super::example_2::Monster::init_from_table(u)) self.any_unique().map(super::example_2::Monster::init_from_table)
} else { } else {
None None
} }
@@ -1436,7 +1424,7 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn any_ambiguous_as_m1(&self) -> Option<Monster<'a>> { pub fn any_ambiguous_as_m1(&self) -> Option<Monster<'a>> {
if self.any_ambiguous_type() == AnyAmbiguousAliases::M1 { if self.any_ambiguous_type() == AnyAmbiguousAliases::M1 {
self.any_ambiguous().map(|u| Monster::init_from_table(u)) self.any_ambiguous().map(Monster::init_from_table)
} else { } else {
None None
} }
@@ -1446,7 +1434,7 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn any_ambiguous_as_m2(&self) -> Option<Monster<'a>> { pub fn any_ambiguous_as_m2(&self) -> Option<Monster<'a>> {
if self.any_ambiguous_type() == AnyAmbiguousAliases::M2 { if self.any_ambiguous_type() == AnyAmbiguousAliases::M2 {
self.any_ambiguous().map(|u| Monster::init_from_table(u)) self.any_ambiguous().map(Monster::init_from_table)
} else { } else {
None None
} }
@@ -1456,7 +1444,7 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn any_ambiguous_as_m3(&self) -> Option<Monster<'a>> { pub fn any_ambiguous_as_m3(&self) -> Option<Monster<'a>> {
if self.any_ambiguous_type() == AnyAmbiguousAliases::M3 { if self.any_ambiguous_type() == AnyAmbiguousAliases::M3 {
self.any_ambiguous().map(|u| Monster::init_from_table(u)) self.any_ambiguous().map(Monster::init_from_table)
} else { } else {
None None
} }
@@ -1575,7 +1563,7 @@ pub struct MonsterBuilder<'a: 'b, 'b> {
} }
impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> {
#[inline] #[inline]
pub fn add_pos(&mut self, pos: &'b Vec3) { pub fn add_pos(&mut self, pos: &Vec3) {
self.fbb_.push_slot_always::<&Vec3>(Monster::VT_POS, pos); self.fbb_.push_slot_always::<&Vec3>(Monster::VT_POS, pos);
} }
#[inline] #[inline]
@@ -1793,9 +1781,7 @@ impl<'a> flatbuffers::Follow<'a> for TypeAliases<'a> {
type Inner = TypeAliases<'a>; type Inner = TypeAliases<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }
@@ -2004,19 +1990,19 @@ pub fn get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
flatbuffers::get_size_prefixed_root::<Monster<'a>>(buf) flatbuffers::get_size_prefixed_root::<Monster<'a>>(buf)
} }
pub const MONSTER_IDENTIFIER: &'static str = "MONS"; pub const MONSTER_IDENTIFIER: &str = "MONS";
#[inline] #[inline]
pub fn monster_buffer_has_identifier(buf: &[u8]) -> bool { pub fn monster_buffer_has_identifier(buf: &[u8]) -> bool {
return flatbuffers::buffer_has_identifier(buf, MONSTER_IDENTIFIER, false); flatbuffers::buffer_has_identifier(buf, MONSTER_IDENTIFIER, false)
} }
#[inline] #[inline]
pub fn monster_size_prefixed_buffer_has_identifier(buf: &[u8]) -> bool { pub fn monster_size_prefixed_buffer_has_identifier(buf: &[u8]) -> bool {
return flatbuffers::buffer_has_identifier(buf, MONSTER_IDENTIFIER, true); flatbuffers::buffer_has_identifier(buf, MONSTER_IDENTIFIER, true)
} }
pub const MONSTER_EXTENSION: &'static str = "mon"; pub const MONSTER_EXTENSION: &str = "mon";
#[inline] #[inline]
pub fn finish_monster_buffer<'a, 'b>( pub fn finish_monster_buffer<'a, 'b>(

View File

@@ -77,7 +77,7 @@ pub const ENUM_VALUES_ENUM_IN_NESTED_NS:[EnumInNestedNS; 3] = [
]; ];
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub const ENUM_NAMES_ENUM_IN_NESTED_NS:[&'static str; 3] = [ pub const ENUM_NAMES_ENUM_IN_NESTED_NS: [&str; 3] = [
"A", "A",
"B", "B",
"C" "C"
@@ -134,17 +134,17 @@ impl<'b> flatbuffers::Push for &'b StructInNestedNS {
impl StructInNestedNS { impl StructInNestedNS {
pub fn new<'a>(_a: i32, _b: i32) -> Self { pub fn new(_a: i32, _b: i32) -> Self {
StructInNestedNS { StructInNestedNS {
a_: _a.to_little_endian(), a_: _a.to_little_endian(),
b_: _b.to_little_endian(), b_: _b.to_little_endian(),
} }
} }
pub fn a<'a>(&'a self) -> i32 { pub fn a(&self) -> i32 {
self.a_.from_little_endian() self.a_.from_little_endian()
} }
pub fn b<'a>(&'a self) -> i32 { pub fn b(&self) -> i32 {
self.b_.from_little_endian() self.b_.from_little_endian()
} }
} }
@@ -160,9 +160,7 @@ impl<'a> flatbuffers::Follow<'a> for TableInNestedNS<'a> {
type Inner = TableInNestedNS<'a>; type Inner = TableInNestedNS<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }

View File

@@ -30,9 +30,7 @@ impl<'a> flatbuffers::Follow<'a> for TableInFirstNS<'a> {
type Inner = TableInFirstNS<'a>; type Inner = TableInFirstNS<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }
@@ -101,7 +99,7 @@ impl<'a: 'b, 'b> TableInFirstNSBuilder<'a, 'b> {
self.fbb_.push_slot::<namespace_b::EnumInNestedNS>(TableInFirstNS::VT_FOO_ENUM, foo_enum, namespace_b::EnumInNestedNS::A); self.fbb_.push_slot::<namespace_b::EnumInNestedNS>(TableInFirstNS::VT_FOO_ENUM, foo_enum, namespace_b::EnumInNestedNS::A);
} }
#[inline] #[inline]
pub fn add_foo_struct(&mut self, foo_struct: &'b namespace_b::StructInNestedNS) { 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); self.fbb_.push_slot_always::<&namespace_b::StructInNestedNS>(TableInFirstNS::VT_FOO_STRUCT, foo_struct);
} }
#[inline] #[inline]
@@ -130,9 +128,7 @@ impl<'a> flatbuffers::Follow<'a> for SecondTableInA<'a> {
type Inner = SecondTableInA<'a>; type Inner = SecondTableInA<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }
@@ -218,9 +214,7 @@ impl<'a> flatbuffers::Follow<'a> for TableInC<'a> {
type Inner = TableInC<'a>; type Inner = TableInC<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }

View File

@@ -28,9 +28,7 @@ impl<'a> flatbuffers::Follow<'a> for ScalarStuff<'a> {
type Inner = ScalarStuff<'a>; type Inner = ScalarStuff<'a>;
#[inline] #[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { Self { _tab: flatbuffers::Table { buf, loc } }
_tab: flatbuffers::Table { buf: buf, loc: loc },
}
} }
} }