Refactor idl_gen_rust and Rust generated code to use consistent whitespace (#6809)

* Remove dead code in idl_gen_rust

* Use 2space indentation in mod.rs

* use In/DecrementIdentValue in idl_gen_rust

Fix some whitespace too in generated code.

* make default fn 2space ident

* More 2space formatting

* git clang format

* make vs2015 happy

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2021-08-23 18:53:10 -04:00
committed by GitHub
parent 273f6084e5
commit f89e0b1a6c
42 changed files with 1904 additions and 1879 deletions

View File

@@ -1,24 +1,24 @@
// Automatically generated by the Flatbuffers compiler. Do not modify.
pub mod namespace_a {
use super::*;
pub mod namespace_b {
use super::*;
pub mod namespace_b {
use super::*;
mod union_in_nested_ns_generated;
pub use self::union_in_nested_ns_generated::*;
mod enum_in_nested_ns_generated;
pub use self::enum_in_nested_ns_generated::*;
mod table_in_nested_ns_generated;
pub use self::table_in_nested_ns_generated::*;
mod struct_in_nested_ns_generated;
pub use self::struct_in_nested_ns_generated::*;
} // namespace_b
mod table_in_first_ns_generated;
pub use self::table_in_first_ns_generated::*;
mod second_table_in_a_generated;
pub use self::second_table_in_a_generated::*;
mod union_in_nested_ns_generated;
pub use self::union_in_nested_ns_generated::*;
mod enum_in_nested_ns_generated;
pub use self::enum_in_nested_ns_generated::*;
mod table_in_nested_ns_generated;
pub use self::table_in_nested_ns_generated::*;
mod struct_in_nested_ns_generated;
pub use self::struct_in_nested_ns_generated::*;
} // namespace_b
mod table_in_first_ns_generated;
pub use self::table_in_first_ns_generated::*;
mod second_table_in_a_generated;
pub use self::second_table_in_a_generated::*;
} // namespace_a
pub mod namespace_c {
use super::*;
mod table_in_c_generated;
pub use self::table_in_c_generated::*;
use super::*;
mod table_in_c_generated;
pub use self::table_in_c_generated::*;
} // namespace_c

View File

@@ -81,9 +81,9 @@ impl<'a> StructInNestedNS {
s
}
pub const fn get_fully_qualified_name() -> &'static str {
"NamespaceA.NamespaceB.StructInNestedNS"
}
pub const fn get_fully_qualified_name() -> &'static str {
"NamespaceA.NamespaceB.StructInNestedNS"
}
pub fn a(&self) -> i32 {
let mut mem = core::mem::MaybeUninit::<i32>::uninit();

View File

@@ -12,38 +12,40 @@ pub struct TableInNestedNS<'a> {
}
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, loc } }
}
type Inner = TableInNestedNS<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
}
}
impl<'a> TableInNestedNS<'a> {
pub const fn get_fully_qualified_name() -> &'static str {
"NamespaceA.NamespaceB.TableInNestedNS"
}
pub const VT_FOO: flatbuffers::VOffsetT = 4;
#[inline]
pub 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>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args TableInNestedNSArgs) -> flatbuffers::WIPOffset<TableInNestedNS<'bldr>> {
let mut builder = TableInNestedNSBuilder::new(_fbb);
builder.add_foo(args.foo);
builder.finish()
}
pub const fn get_fully_qualified_name() -> &'static str {
"NamespaceA.NamespaceB.TableInNestedNS"
}
pub fn unpack(&self) -> TableInNestedNST {
let foo = self.foo();
TableInNestedNST {
foo,
}
#[inline]
pub 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>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args TableInNestedNSArgs
) -> flatbuffers::WIPOffset<TableInNestedNS<'bldr>> {
let mut builder = TableInNestedNSBuilder::new(_fbb);
builder.add_foo(args.foo);
builder.finish()
}
pub fn unpack(&self) -> TableInNestedNST {
let foo = self.foo();
TableInNestedNST {
foo,
}
pub const VT_FOO: flatbuffers::VOffsetT = 4;
}
#[inline]
pub fn foo(&self) -> i32 {
@@ -67,12 +69,12 @@ pub struct TableInNestedNSArgs {
pub foo: i32,
}
impl<'a> Default for TableInNestedNSArgs {
#[inline]
fn default() -> Self {
TableInNestedNSArgs {
foo: 0,
}
#[inline]
fn default() -> Self {
TableInNestedNSArgs {
foo: 0,
}
}
}
pub struct TableInNestedNSBuilder<'a: 'b, 'b> {
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,

View File

@@ -12,40 +12,42 @@ pub struct SecondTableInA<'a> {
}
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, loc } }
}
type Inner = SecondTableInA<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
}
}
impl<'a> SecondTableInA<'a> {
pub const fn get_fully_qualified_name() -> &'static str {
"NamespaceA.SecondTableInA"
}
pub const VT_REFER_TO_C: flatbuffers::VOffsetT = 4;
#[inline]
pub 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>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args SecondTableInAArgs<'args>) -> flatbuffers::WIPOffset<SecondTableInA<'bldr>> {
let mut builder = SecondTableInABuilder::new(_fbb);
if let Some(x) = args.refer_to_c { builder.add_refer_to_c(x); }
builder.finish()
}
pub const fn get_fully_qualified_name() -> &'static str {
"NamespaceA.SecondTableInA"
}
pub fn unpack(&self) -> SecondTableInAT {
let refer_to_c = self.refer_to_c().map(|x| {
Box::new(x.unpack())
});
SecondTableInAT {
refer_to_c,
}
#[inline]
pub 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>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args SecondTableInAArgs<'args>
) -> flatbuffers::WIPOffset<SecondTableInA<'bldr>> {
let mut builder = SecondTableInABuilder::new(_fbb);
if let Some(x) = args.refer_to_c { builder.add_refer_to_c(x); }
builder.finish()
}
pub fn unpack(&self) -> SecondTableInAT {
let refer_to_c = self.refer_to_c().map(|x| {
Box::new(x.unpack())
});
SecondTableInAT {
refer_to_c,
}
pub const VT_REFER_TO_C: flatbuffers::VOffsetT = 4;
}
#[inline]
pub fn refer_to_c(&self) -> Option<super::namespace_c::TableInC<'a>> {
@@ -69,12 +71,12 @@ pub struct SecondTableInAArgs<'a> {
pub refer_to_c: Option<flatbuffers::WIPOffset<super::namespace_c::TableInC<'a>>>,
}
impl<'a> Default for SecondTableInAArgs<'a> {
#[inline]
fn default() -> Self {
SecondTableInAArgs {
refer_to_c: None,
}
#[inline]
fn default() -> Self {
SecondTableInAArgs {
refer_to_c: None,
}
}
}
pub struct SecondTableInABuilder<'a: 'b, 'b> {
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,

View File

@@ -12,64 +12,66 @@ pub struct TableInFirstNS<'a> {
}
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, loc } }
}
type Inner = TableInFirstNS<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
}
}
impl<'a> TableInFirstNS<'a> {
pub const fn get_fully_qualified_name() -> &'static str {
"NamespaceA.TableInFirstNS"
}
pub const VT_FOO_TABLE: flatbuffers::VOffsetT = 4;
pub const VT_FOO_ENUM: flatbuffers::VOffsetT = 6;
pub const VT_FOO_UNION_TYPE: flatbuffers::VOffsetT = 8;
pub const VT_FOO_UNION: flatbuffers::VOffsetT = 10;
pub const VT_FOO_STRUCT: flatbuffers::VOffsetT = 12;
#[inline]
pub 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>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args TableInFirstNSArgs<'args>) -> flatbuffers::WIPOffset<TableInFirstNS<'bldr>> {
let mut builder = TableInFirstNSBuilder::new(_fbb);
if let Some(x) = args.foo_struct { builder.add_foo_struct(x); }
if let Some(x) = args.foo_union { builder.add_foo_union(x); }
if let Some(x) = args.foo_table { builder.add_foo_table(x); }
builder.add_foo_union_type(args.foo_union_type);
builder.add_foo_enum(args.foo_enum);
builder.finish()
}
pub const fn get_fully_qualified_name() -> &'static str {
"NamespaceA.TableInFirstNS"
}
pub fn unpack(&self) -> TableInFirstNST {
let foo_table = self.foo_table().map(|x| {
Box::new(x.unpack())
});
let foo_enum = self.foo_enum();
let foo_union = match self.foo_union_type() {
namespace_b::UnionInNestedNS::NONE => namespace_b::UnionInNestedNST::NONE,
namespace_b::UnionInNestedNS::TableInNestedNS => namespace_b::UnionInNestedNST::TableInNestedNS(Box::new(
self.foo_union_as_table_in_nested_ns()
.expect("Invalid union table, expected `namespace_b::UnionInNestedNS::TableInNestedNS`.")
.unpack()
)),
_ => namespace_b::UnionInNestedNST::NONE,
};
let foo_struct = self.foo_struct().map(|x| {
x.unpack()
});
TableInFirstNST {
foo_table,
foo_enum,
foo_union,
foo_struct,
}
#[inline]
pub 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>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args TableInFirstNSArgs<'args>
) -> flatbuffers::WIPOffset<TableInFirstNS<'bldr>> {
let mut builder = TableInFirstNSBuilder::new(_fbb);
if let Some(x) = args.foo_struct { builder.add_foo_struct(x); }
if let Some(x) = args.foo_union { builder.add_foo_union(x); }
if let Some(x) = args.foo_table { builder.add_foo_table(x); }
builder.add_foo_union_type(args.foo_union_type);
builder.add_foo_enum(args.foo_enum);
builder.finish()
}
pub fn unpack(&self) -> TableInFirstNST {
let foo_table = self.foo_table().map(|x| {
Box::new(x.unpack())
});
let foo_enum = self.foo_enum();
let foo_union = match self.foo_union_type() {
namespace_b::UnionInNestedNS::NONE => namespace_b::UnionInNestedNST::NONE,
namespace_b::UnionInNestedNS::TableInNestedNS => namespace_b::UnionInNestedNST::TableInNestedNS(Box::new(
self.foo_union_as_table_in_nested_ns()
.expect("Invalid union table, expected `namespace_b::UnionInNestedNS::TableInNestedNS`.")
.unpack()
)),
_ => namespace_b::UnionInNestedNST::NONE,
};
let foo_struct = self.foo_struct().map(|x| {
x.unpack()
});
TableInFirstNST {
foo_table,
foo_enum,
foo_union,
foo_struct,
}
pub const VT_FOO_TABLE: flatbuffers::VOffsetT = 4;
pub const VT_FOO_ENUM: flatbuffers::VOffsetT = 6;
pub const VT_FOO_UNION_TYPE: flatbuffers::VOffsetT = 8;
pub const VT_FOO_UNION: flatbuffers::VOffsetT = 10;
pub const VT_FOO_STRUCT: flatbuffers::VOffsetT = 12;
}
#[inline]
pub fn foo_table(&self) -> Option<namespace_b::TableInNestedNS<'a>> {
@@ -131,16 +133,16 @@ pub struct TableInFirstNSArgs<'a> {
pub foo_struct: Option<&'a namespace_b::StructInNestedNS>,
}
impl<'a> Default for TableInFirstNSArgs<'a> {
#[inline]
fn default() -> Self {
TableInFirstNSArgs {
foo_table: None,
foo_enum: namespace_b::EnumInNestedNS::A,
foo_union_type: namespace_b::UnionInNestedNS::NONE,
foo_union: None,
foo_struct: None,
}
#[inline]
fn default() -> Self {
TableInFirstNSArgs {
foo_table: None,
foo_enum: namespace_b::EnumInNestedNS::A,
foo_union_type: namespace_b::UnionInNestedNS::NONE,
foo_union: None,
foo_struct: None,
}
}
}
pub struct TableInFirstNSBuilder<'a: 'b, 'b> {
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,

View File

@@ -12,46 +12,48 @@ pub struct TableInC<'a> {
}
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, loc } }
}
type Inner = TableInC<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
}
}
impl<'a> TableInC<'a> {
pub const fn get_fully_qualified_name() -> &'static str {
"NamespaceC.TableInC"
}
pub const VT_REFER_TO_A1: flatbuffers::VOffsetT = 4;
pub const VT_REFER_TO_A2: flatbuffers::VOffsetT = 6;
#[inline]
pub 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>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args TableInCArgs<'args>) -> flatbuffers::WIPOffset<TableInC<'bldr>> {
let mut builder = TableInCBuilder::new(_fbb);
if let Some(x) = args.refer_to_a2 { builder.add_refer_to_a2(x); }
if let Some(x) = args.refer_to_a1 { builder.add_refer_to_a1(x); }
builder.finish()
}
pub const fn get_fully_qualified_name() -> &'static str {
"NamespaceC.TableInC"
}
pub fn unpack(&self) -> TableInCT {
let refer_to_a1 = self.refer_to_a1().map(|x| {
Box::new(x.unpack())
});
let refer_to_a2 = self.refer_to_a2().map(|x| {
Box::new(x.unpack())
});
TableInCT {
refer_to_a1,
refer_to_a2,
}
#[inline]
pub 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>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args TableInCArgs<'args>
) -> flatbuffers::WIPOffset<TableInC<'bldr>> {
let mut builder = TableInCBuilder::new(_fbb);
if let Some(x) = args.refer_to_a2 { builder.add_refer_to_a2(x); }
if let Some(x) = args.refer_to_a1 { builder.add_refer_to_a1(x); }
builder.finish()
}
pub fn unpack(&self) -> TableInCT {
let refer_to_a1 = self.refer_to_a1().map(|x| {
Box::new(x.unpack())
});
let refer_to_a2 = self.refer_to_a2().map(|x| {
Box::new(x.unpack())
});
TableInCT {
refer_to_a1,
refer_to_a2,
}
pub const VT_REFER_TO_A1: flatbuffers::VOffsetT = 4;
pub const VT_REFER_TO_A2: flatbuffers::VOffsetT = 6;
}
#[inline]
pub fn refer_to_a1(&self) -> Option<super::namespace_a::TableInFirstNS<'a>> {
@@ -81,13 +83,13 @@ pub struct TableInCArgs<'a> {
pub refer_to_a2: Option<flatbuffers::WIPOffset<super::namespace_a::SecondTableInA<'a>>>,
}
impl<'a> Default for TableInCArgs<'a> {
#[inline]
fn default() -> Self {
TableInCArgs {
refer_to_a1: None,
refer_to_a2: None,
}
#[inline]
fn default() -> Self {
TableInCArgs {
refer_to_a1: None,
refer_to_a2: None,
}
}
}
pub struct TableInCBuilder<'a: 'b, 'b> {
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,