mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-06 16:42:09 +00:00
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:
@@ -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
|
||||
/// programming patterns more ergonomic.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct FollowStart<T>(PhantomData<T>);
|
||||
impl<'a, T: Follow<'a> + 'a> FollowStart<T> {
|
||||
#[inline]
|
||||
|
||||
@@ -616,7 +616,7 @@ class RustGenerator : public BaseGenerator {
|
||||
static const uint64_t kMaxSparseness = 5;
|
||||
if (range / static_cast<uint64_t>(enum_def.size()) < kMaxSparseness) {
|
||||
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) + "] = [";
|
||||
|
||||
auto val = enum_def.Vals().front();
|
||||
@@ -736,7 +736,6 @@ class RustGenerator : public BaseGenerator {
|
||||
const auto typname = GetTypeBasic(type.VectorType());
|
||||
return "Option<flatbuffers::WIPOffset<flatbuffers::Vector<" + lifetime +
|
||||
", " + typname + ">>>";
|
||||
// TODO(cneo): Fix whitespace in generated code.
|
||||
}
|
||||
case ftVectorOfEnumKey: {
|
||||
const auto typname = WrapInNameSpace(*type.enum_def);
|
||||
@@ -832,7 +831,7 @@ class RustGenerator : public BaseGenerator {
|
||||
}
|
||||
case ftStruct: {
|
||||
const auto typname = WrapInNameSpace(*type.struct_def);
|
||||
return "&" + lifetime + " " + typname + "";
|
||||
return "&" + typname + "";
|
||||
}
|
||||
case ftTable: {
|
||||
const auto typname = WrapInNameSpace(*type.struct_def);
|
||||
@@ -1137,9 +1136,7 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += " type Inner = {{STRUCT_NAME}}<'a>;";
|
||||
code_ += " #[inline]";
|
||||
code_ += " fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
|
||||
code_ += " Self {";
|
||||
code_ += " _tab: flatbuffers::Table { buf: buf, loc: loc },";
|
||||
code_ += " }";
|
||||
code_ += " Self { _tab: flatbuffers::Table { buf, loc } }";
|
||||
code_ += " }";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
@@ -1335,8 +1332,8 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += " Some({{U_ELEMENT_TABLE_TYPE}}::init_from_table(u))";
|
||||
} else {
|
||||
code_ +=
|
||||
" self.{{FIELD_NAME}}().map(|u| "
|
||||
"{{U_ELEMENT_TABLE_TYPE}}::init_from_table(u))";
|
||||
" self.{{FIELD_NAME}}().map("
|
||||
"{{U_ELEMENT_TABLE_TYPE}}::init_from_table)";
|
||||
}
|
||||
code_ += " } else {";
|
||||
code_ += " None";
|
||||
@@ -1523,7 +1520,8 @@ class RustGenerator : public BaseGenerator {
|
||||
|
||||
if (parser_.file_identifier_.length()) {
|
||||
// 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_ += "";
|
||||
|
||||
@@ -1531,22 +1529,22 @@ class RustGenerator : public BaseGenerator {
|
||||
code_ += "#[inline]";
|
||||
code_ += "pub fn {{STRUCT_NAME_SNAKECASE}}_buffer_has_identifier\\";
|
||||
code_ += "(buf: &[u8]) -> bool {";
|
||||
code_ += " return flatbuffers::buffer_has_identifier(buf, \\";
|
||||
code_ += "{{STRUCT_NAME_CAPS}}_IDENTIFIER, false);";
|
||||
code_ += " flatbuffers::buffer_has_identifier(buf, \\";
|
||||
code_ += "{{STRUCT_NAME_CAPS}}_IDENTIFIER, false)";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
code_ += "#[inline]";
|
||||
code_ += "pub fn {{STRUCT_NAME_SNAKECASE}}_size_prefixed\\";
|
||||
code_ += "_buffer_has_identifier(buf: &[u8]) -> bool {";
|
||||
code_ += " return flatbuffers::buffer_has_identifier(buf, \\";
|
||||
code_ += "{{STRUCT_NAME_CAPS}}_IDENTIFIER, true);";
|
||||
code_ += " flatbuffers::buffer_has_identifier(buf, \\";
|
||||
code_ += "{{STRUCT_NAME_CAPS}}_IDENTIFIER, true)";
|
||||
code_ += "}";
|
||||
code_ += "";
|
||||
}
|
||||
|
||||
if (parser_.file_extension_.length()) {
|
||||
// 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_ += "";
|
||||
}
|
||||
@@ -1694,7 +1692,7 @@ class RustGenerator : public BaseGenerator {
|
||||
const auto &field = **it;
|
||||
const auto member_name = Name(field) + "_";
|
||||
const auto reference =
|
||||
StructMemberAccessNeedsCopy(field.value.type) ? "" : "&'a ";
|
||||
StructMemberAccessNeedsCopy(field.value.type) ? "" : "&";
|
||||
const auto arg_name = "_" + Name(field);
|
||||
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("INIT_LIST", init_list);
|
||||
code_ += " pub fn new<'a>({{ARG_LIST}}) -> Self {";
|
||||
code_ += " pub fn new({{ARG_LIST}}) -> Self {";
|
||||
code_ += " {{STRUCT_NAME}} {";
|
||||
code_ += "{{INIT_LIST}}";
|
||||
padding_id = 0;
|
||||
@@ -1745,12 +1743,16 @@ class RustGenerator : public BaseGenerator {
|
||||
code_.SetValue("FIELD_NAME", Name(field));
|
||||
code_.SetValue("FIELD_TYPE", field_type);
|
||||
code_.SetValue("FIELD_VALUE", value);
|
||||
code_.SetValue("REF", IsStruct(field.value.type) ? "&" : "");
|
||||
|
||||
GenComment(field.doc_comment, " ");
|
||||
code_ += " pub fn {{FIELD_NAME}}<'a>(&'a self) -> {{FIELD_TYPE}} {";
|
||||
code_ += " {{REF}}{{FIELD_VALUE}}";
|
||||
if (IsStruct(field.value.type)) {
|
||||
code_ += " pub fn {{FIELD_NAME}}(&self) -> {{FIELD_TYPE}} {";
|
||||
code_ += " &{{FIELD_VALUE}}";
|
||||
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.
|
||||
if (field.key) { GenKeyFieldMethods(field); }
|
||||
|
||||
@@ -20,9 +20,7 @@ impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
|
||||
type Inner = TableA<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ pub const ENUM_VALUES_FROM_INCLUDE:[FromInclude; 1] = [
|
||||
];
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub const ENUM_NAMES_FROM_INCLUDE:[&'static str; 1] = [
|
||||
pub const ENUM_NAMES_FROM_INCLUDE: [&str; 1] = [
|
||||
"IncludeVal"
|
||||
];
|
||||
|
||||
@@ -130,13 +130,13 @@ impl<'b> flatbuffers::Push for &'b Unused {
|
||||
|
||||
|
||||
impl Unused {
|
||||
pub fn new<'a>(_a: i32) -> Self {
|
||||
pub fn new(_a: i32) -> Self {
|
||||
Unused {
|
||||
a_: _a.to_little_endian(),
|
||||
|
||||
}
|
||||
}
|
||||
pub fn a<'a>(&'a self) -> i32 {
|
||||
pub fn a(&self) -> i32 {
|
||||
self.a_.from_little_endian()
|
||||
}
|
||||
}
|
||||
@@ -152,9 +152,7 @@ impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
|
||||
type Inner = TableB<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,7 @@ impl<'a> flatbuffers::Follow<'a> for InParentNamespace<'a> {
|
||||
type Inner = InParentNamespace<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,9 +108,7 @@ impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
|
||||
type Inner = Monster<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +231,7 @@ pub const ENUM_VALUES_COLOR:[Color; 3] = [
|
||||
];
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub const ENUM_NAMES_COLOR:[&'static str; 8] = [
|
||||
pub const ENUM_NAMES_COLOR: [&str; 8] = [
|
||||
"Red",
|
||||
"Green",
|
||||
"",
|
||||
@@ -305,7 +301,7 @@ pub const ENUM_VALUES_RACE:[Race; 4] = [
|
||||
];
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub const ENUM_NAMES_RACE:[&'static str; 4] = [
|
||||
pub const ENUM_NAMES_RACE: [&str; 4] = [
|
||||
"None",
|
||||
"Human",
|
||||
"Dwarf",
|
||||
@@ -371,7 +367,7 @@ pub const ENUM_VALUES_ANY:[Any; 4] = [
|
||||
];
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub const ENUM_NAMES_ANY:[&'static str; 4] = [
|
||||
pub const ENUM_NAMES_ANY: [&str; 4] = [
|
||||
"NONE",
|
||||
"Monster",
|
||||
"TestSimpleTableWithEnum",
|
||||
@@ -438,7 +434,7 @@ pub const ENUM_VALUES_ANY_UNIQUE_ALIASES:[AnyUniqueAliases; 4] = [
|
||||
];
|
||||
|
||||
#[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",
|
||||
"M",
|
||||
"TS",
|
||||
@@ -505,7 +501,7 @@ pub const ENUM_VALUES_ANY_AMBIGUOUS_ALIASES:[AnyAmbiguousAliases; 4] = [
|
||||
];
|
||||
|
||||
#[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",
|
||||
"M1",
|
||||
"M2",
|
||||
@@ -565,7 +561,7 @@ impl<'b> flatbuffers::Push for &'b Test {
|
||||
|
||||
|
||||
impl Test {
|
||||
pub fn new<'a>(_a: i16, _b: i8) -> Self {
|
||||
pub fn new(_a: i16, _b: i8) -> Self {
|
||||
Test {
|
||||
a_: _a.to_little_endian(),
|
||||
b_: _b.to_little_endian(),
|
||||
@@ -577,10 +573,10 @@ impl Test {
|
||||
"MyGame.Example.Test"
|
||||
}
|
||||
|
||||
pub fn a<'a>(&'a self) -> i16 {
|
||||
pub fn a(&self) -> i16 {
|
||||
self.a_.from_little_endian()
|
||||
}
|
||||
pub fn b<'a>(&'a self) -> i8 {
|
||||
pub fn b(&self) -> i8 {
|
||||
self.b_.from_little_endian()
|
||||
}
|
||||
}
|
||||
@@ -638,7 +634,7 @@ impl<'b> flatbuffers::Push for &'b 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 {
|
||||
x_: _x.to_little_endian(),
|
||||
y_: _y.to_little_endian(),
|
||||
@@ -656,22 +652,22 @@ impl Vec3 {
|
||||
"MyGame.Example.Vec3"
|
||||
}
|
||||
|
||||
pub fn x<'a>(&'a self) -> f32 {
|
||||
pub fn x(&self) -> f32 {
|
||||
self.x_.from_little_endian()
|
||||
}
|
||||
pub fn y<'a>(&'a self) -> f32 {
|
||||
pub fn y(&self) -> f32 {
|
||||
self.y_.from_little_endian()
|
||||
}
|
||||
pub fn z<'a>(&'a self) -> f32 {
|
||||
pub fn z(&self) -> f32 {
|
||||
self.z_.from_little_endian()
|
||||
}
|
||||
pub fn test1<'a>(&'a self) -> f64 {
|
||||
pub fn test1(&self) -> f64 {
|
||||
self.test1_.from_little_endian()
|
||||
}
|
||||
pub fn test2<'a>(&'a self) -> Color {
|
||||
pub fn test2(&self) -> Color {
|
||||
self.test2_.from_little_endian()
|
||||
}
|
||||
pub fn test3<'a>(&'a self) -> &'a Test {
|
||||
pub fn test3(&self) -> &Test {
|
||||
&self.test3_
|
||||
}
|
||||
}
|
||||
@@ -722,7 +718,7 @@ impl<'b> flatbuffers::Push for &'b Ability {
|
||||
|
||||
|
||||
impl Ability {
|
||||
pub fn new<'a>(_id: u32, _distance: u32) -> Self {
|
||||
pub fn new(_id: u32, _distance: u32) -> Self {
|
||||
Ability {
|
||||
id_: _id.to_little_endian(),
|
||||
distance_: _distance.to_little_endian(),
|
||||
@@ -733,7 +729,7 @@ impl Ability {
|
||||
"MyGame.Example.Ability"
|
||||
}
|
||||
|
||||
pub fn id<'a>(&'a self) -> u32 {
|
||||
pub fn id(&self) -> u32 {
|
||||
self.id_.from_little_endian()
|
||||
}
|
||||
#[inline]
|
||||
@@ -746,7 +742,7 @@ impl Ability {
|
||||
let key = self.id();
|
||||
key.cmp(&val)
|
||||
}
|
||||
pub fn distance<'a>(&'a self) -> u32 {
|
||||
pub fn distance(&self) -> u32 {
|
||||
self.distance_.from_little_endian()
|
||||
}
|
||||
}
|
||||
@@ -762,9 +758,7 @@ impl<'a> flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> {
|
||||
type Inner = TestSimpleTableWithEnum<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -842,9 +836,7 @@ impl<'a> flatbuffers::Follow<'a> for Stat<'a> {
|
||||
type Inner = Stat<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -946,9 +938,7 @@ impl<'a> flatbuffers::Follow<'a> for Referrable<'a> {
|
||||
type Inner = Referrable<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1037,9 +1027,7 @@ impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
|
||||
type Inner = Monster<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1376,7 +1364,7 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn test_as_monster(&self) -> Option<Monster<'a>> {
|
||||
if self.test_type() == Any::Monster {
|
||||
self.test().map(|u| Monster::init_from_table(u))
|
||||
self.test().map(Monster::init_from_table)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -1386,7 +1374,7 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn test_as_test_simple_table_with_enum(&self) -> Option<TestSimpleTableWithEnum<'a>> {
|
||||
if self.test_type() == Any::TestSimpleTableWithEnum {
|
||||
self.test().map(|u| TestSimpleTableWithEnum::init_from_table(u))
|
||||
self.test().map(TestSimpleTableWithEnum::init_from_table)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -1396,7 +1384,7 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn test_as_my_game_example_2_monster(&self) -> Option<super::example_2::Monster<'a>> {
|
||||
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 {
|
||||
None
|
||||
}
|
||||
@@ -1406,7 +1394,7 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_unique_as_m(&self) -> Option<Monster<'a>> {
|
||||
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 {
|
||||
None
|
||||
}
|
||||
@@ -1416,7 +1404,7 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_unique_as_ts(&self) -> Option<TestSimpleTableWithEnum<'a>> {
|
||||
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 {
|
||||
None
|
||||
}
|
||||
@@ -1426,7 +1414,7 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_unique_as_m2(&self) -> Option<super::example_2::Monster<'a>> {
|
||||
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 {
|
||||
None
|
||||
}
|
||||
@@ -1436,7 +1424,7 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_ambiguous_as_m1(&self) -> Option<Monster<'a>> {
|
||||
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 {
|
||||
None
|
||||
}
|
||||
@@ -1446,7 +1434,7 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_ambiguous_as_m2(&self) -> Option<Monster<'a>> {
|
||||
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 {
|
||||
None
|
||||
}
|
||||
@@ -1456,7 +1444,7 @@ impl<'a> Monster<'a> {
|
||||
#[allow(non_snake_case)]
|
||||
pub fn any_ambiguous_as_m3(&self) -> Option<Monster<'a>> {
|
||||
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 {
|
||||
None
|
||||
}
|
||||
@@ -1575,7 +1563,7 @@ pub struct MonsterBuilder<'a: 'b, 'b> {
|
||||
}
|
||||
impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> {
|
||||
#[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);
|
||||
}
|
||||
#[inline]
|
||||
@@ -1793,9 +1781,7 @@ impl<'a> flatbuffers::Follow<'a> for TypeAliases<'a> {
|
||||
type Inner = TypeAliases<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, 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)
|
||||
}
|
||||
|
||||
pub const MONSTER_IDENTIFIER: &'static str = "MONS";
|
||||
pub const MONSTER_IDENTIFIER: &str = "MONS";
|
||||
|
||||
#[inline]
|
||||
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]
|
||||
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]
|
||||
pub fn finish_monster_buffer<'a, 'b>(
|
||||
|
||||
@@ -77,7 +77,7 @@ pub const ENUM_VALUES_ENUM_IN_NESTED_NS:[EnumInNestedNS; 3] = [
|
||||
];
|
||||
|
||||
#[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",
|
||||
"B",
|
||||
"C"
|
||||
@@ -134,17 +134,17 @@ impl<'b> flatbuffers::Push for &'b StructInNestedNS {
|
||||
|
||||
|
||||
impl StructInNestedNS {
|
||||
pub fn new<'a>(_a: i32, _b: i32) -> Self {
|
||||
pub fn new(_a: i32, _b: i32) -> Self {
|
||||
StructInNestedNS {
|
||||
a_: _a.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()
|
||||
}
|
||||
pub fn b<'a>(&'a self) -> i32 {
|
||||
pub fn b(&self) -> i32 {
|
||||
self.b_.from_little_endian()
|
||||
}
|
||||
}
|
||||
@@ -160,9 +160,7 @@ impl<'a> flatbuffers::Follow<'a> for TableInNestedNS<'a> {
|
||||
type Inner = TableInNestedNS<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,7 @@ impl<'a> flatbuffers::Follow<'a> for TableInFirstNS<'a> {
|
||||
type Inner = TableInFirstNS<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, 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);
|
||||
}
|
||||
#[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);
|
||||
}
|
||||
#[inline]
|
||||
@@ -130,9 +128,7 @@ impl<'a> flatbuffers::Follow<'a> for SecondTableInA<'a> {
|
||||
type Inner = SecondTableInA<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,9 +214,7 @@ impl<'a> flatbuffers::Follow<'a> for TableInC<'a> {
|
||||
type Inner = TableInC<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,7 @@ impl<'a> flatbuffers::Follow<'a> for ScalarStuff<'a> {
|
||||
type Inner = ScalarStuff<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user