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

@@ -12,44 +12,46 @@ pub struct Weapon<'a> {
}
impl<'a> flatbuffers::Follow<'a> for Weapon<'a> {
type Inner = Weapon<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
}
type Inner = Weapon<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
}
}
impl<'a> Weapon<'a> {
pub const fn get_fully_qualified_name() -> &'static str {
"MyGame.Sample.Weapon"
}
pub const VT_NAME: flatbuffers::VOffsetT = 4;
pub const VT_DAMAGE: flatbuffers::VOffsetT = 6;
#[inline]
pub 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>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args WeaponArgs<'args>) -> flatbuffers::WIPOffset<Weapon<'bldr>> {
let mut builder = WeaponBuilder::new(_fbb);
if let Some(x) = args.name { builder.add_name(x); }
builder.add_damage(args.damage);
builder.finish()
}
pub const fn get_fully_qualified_name() -> &'static str {
"MyGame.Sample.Weapon"
}
pub fn unpack(&self) -> WeaponT {
let name = self.name().map(|x| {
x.to_string()
});
let damage = self.damage();
WeaponT {
name,
damage,
}
#[inline]
pub 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>(
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
args: &'args WeaponArgs<'args>
) -> flatbuffers::WIPOffset<Weapon<'bldr>> {
let mut builder = WeaponBuilder::new(_fbb);
if let Some(x) = args.name { builder.add_name(x); }
builder.add_damage(args.damage);
builder.finish()
}
pub fn unpack(&self) -> WeaponT {
let name = self.name().map(|x| {
x.to_string()
});
let damage = self.damage();
WeaponT {
name,
damage,
}
pub const VT_NAME: flatbuffers::VOffsetT = 4;
pub const VT_DAMAGE: flatbuffers::VOffsetT = 6;
}
#[inline]
pub fn name(&self) -> Option<&'a str> {
@@ -79,13 +81,13 @@ pub struct WeaponArgs<'a> {
pub damage: i16,
}
impl<'a> Default for WeaponArgs<'a> {
#[inline]
fn default() -> Self {
WeaponArgs {
name: None,
damage: 0,
}
#[inline]
fn default() -> Self {
WeaponArgs {
name: None,
damage: 0,
}
}
}
pub struct WeaponBuilder<'a: 'b, 'b> {
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,