mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-27 11:52:18 +00:00
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:
@@ -12,48 +12,50 @@ pub struct Stat<'a> {
|
||||
}
|
||||
|
||||
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, loc } }
|
||||
}
|
||||
type Inner = Stat<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table { buf, loc } }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Stat<'a> {
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"MyGame.Example.Stat"
|
||||
}
|
||||
pub const VT_ID: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_VAL: flatbuffers::VOffsetT = 6;
|
||||
pub const VT_COUNT: flatbuffers::VOffsetT = 8;
|
||||
|
||||
#[inline]
|
||||
pub 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>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args StatArgs<'args>) -> flatbuffers::WIPOffset<Stat<'bldr>> {
|
||||
let mut builder = StatBuilder::new(_fbb);
|
||||
builder.add_val(args.val);
|
||||
if let Some(x) = args.id { builder.add_id(x); }
|
||||
builder.add_count(args.count);
|
||||
builder.finish()
|
||||
}
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"MyGame.Example.Stat"
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> StatT {
|
||||
let id = self.id().map(|x| {
|
||||
x.to_string()
|
||||
});
|
||||
let val = self.val();
|
||||
let count = self.count();
|
||||
StatT {
|
||||
id,
|
||||
val,
|
||||
count,
|
||||
}
|
||||
#[inline]
|
||||
pub 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>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args StatArgs<'args>
|
||||
) -> flatbuffers::WIPOffset<Stat<'bldr>> {
|
||||
let mut builder = StatBuilder::new(_fbb);
|
||||
builder.add_val(args.val);
|
||||
if let Some(x) = args.id { builder.add_id(x); }
|
||||
builder.add_count(args.count);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> StatT {
|
||||
let id = self.id().map(|x| {
|
||||
x.to_string()
|
||||
});
|
||||
let val = self.val();
|
||||
let count = self.count();
|
||||
StatT {
|
||||
id,
|
||||
val,
|
||||
count,
|
||||
}
|
||||
pub const VT_ID: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_VAL: flatbuffers::VOffsetT = 6;
|
||||
pub const VT_COUNT: flatbuffers::VOffsetT = 8;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> Option<&'a str> {
|
||||
@@ -68,12 +70,12 @@ impl<'a> Stat<'a> {
|
||||
self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()
|
||||
}
|
||||
#[inline]
|
||||
pub fn key_compare_less_than(&self, o: &Stat) -> bool {
|
||||
pub fn key_compare_less_than(&self, o: &Stat) -> bool {
|
||||
self.count() < o.count()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn key_compare_with_value(&self, val: u16) -> ::std::cmp::Ordering {
|
||||
pub fn key_compare_with_value(&self, val: u16) -> ::std::cmp::Ordering {
|
||||
let key = self.count();
|
||||
key.cmp(&val)
|
||||
}
|
||||
@@ -99,14 +101,14 @@ pub struct StatArgs<'a> {
|
||||
pub count: u16,
|
||||
}
|
||||
impl<'a> Default for StatArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
StatArgs {
|
||||
id: None,
|
||||
val: 0,
|
||||
count: 0,
|
||||
}
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
StatArgs {
|
||||
id: None,
|
||||
val: 0,
|
||||
count: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct StatBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
|
||||
Reference in New Issue
Block a user