Rust Object API (#6070)

* inital commit of rust object api

* Required fields support.

* clang fallthrough

* Fix unused variables

* just don't fall through

* remove comment

* s/panic/unreachable

* Tests for object API

* Added defaults

* deleted unintentionally added files and updated .bat file

* fix bat file

* clang format

* Cargo clippy checks

* remove commented out code

* clippy allows

* Remove matches! macro since we're not yet at Rust v1.42

* install clippy in RustTest.sh

* move line

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2021-01-22 13:07:32 -05:00
committed by GitHub
parent 796ed68faf
commit 1da0a2dfac
21 changed files with 2362 additions and 319 deletions

View File

@@ -38,7 +38,7 @@ pub const ENUM_VALUES_ENUM_IN_NESTED_NS: [EnumInNestedNS; 3] = [
EnumInNestedNS::C,
];
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct EnumInNestedNS(pub i8);
#[allow(non_upper_case_globals)]
@@ -116,7 +116,7 @@ impl<'a> flatbuffers::Verifiable for EnumInNestedNS {
impl flatbuffers::SimpleToVerifyInSlice for EnumInNestedNS {}
// struct StructInNestedNS, aligned to 4
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq)]
#[derive(Clone, Copy, PartialEq, Default)]
pub struct StructInNestedNS(pub [u8; 8]);
impl std::fmt::Debug for StructInNestedNS {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
@@ -236,6 +236,26 @@ impl StructInNestedNS {
}
}
pub fn unpack(&self) -> StructInNestedNST {
StructInNestedNST {
a: self.a(),
b: self.b(),
}
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct StructInNestedNST {
pub a: i32,
pub b: i32,
}
impl StructInNestedNST {
pub fn pack(&self) -> StructInNestedNS {
StructInNestedNS::new(
self.a,
self.b,
)
}
}
pub enum TableInNestedNSOffset {}
@@ -260,9 +280,7 @@ impl<'a> TableInNestedNS<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableInNestedNS {
_tab: table,
}
TableInNestedNS { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
@@ -273,6 +291,12 @@ impl<'a> TableInNestedNS<'a> {
builder.finish()
}
pub fn unpack(&self) -> TableInNestedNST {
let foo = self.foo();
TableInNestedNST {
foo,
}
}
pub const VT_FOO: flatbuffers::VOffsetT = 4;
#[inline]
@@ -335,6 +359,22 @@ impl std::fmt::Debug for TableInNestedNS<'_> {
ds.finish()
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct TableInNestedNST {
pub foo: i32,
}
impl TableInNestedNST {
pub fn pack<'b>(
&self,
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
) -> flatbuffers::WIPOffset<TableInNestedNS<'b>> {
let foo = self.foo;
TableInNestedNS::create(_fbb, &TableInNestedNSArgs{
foo,
})
}
}
} // pub mod NamespaceB
} // pub mod NamespaceA