mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-15 00:38:52 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -42,9 +42,7 @@ impl<'a> TableInFirstNS<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableInFirstNS {
|
||||
_tab: table,
|
||||
}
|
||||
TableInFirstNS { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
@@ -57,6 +55,20 @@ impl<'a> TableInFirstNS<'a> {
|
||||
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_struct = self.foo_struct().map(|x| {
|
||||
x.unpack()
|
||||
});
|
||||
TableInFirstNST {
|
||||
foo_table,
|
||||
foo_enum,
|
||||
foo_struct,
|
||||
}
|
||||
}
|
||||
pub const VT_FOO_TABLE: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_FOO_ENUM: flatbuffers::VOffsetT = 6;
|
||||
pub const VT_FOO_STRUCT: flatbuffers::VOffsetT = 8;
|
||||
@@ -145,6 +157,31 @@ impl std::fmt::Debug for TableInFirstNS<'_> {
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct TableInFirstNST {
|
||||
pub foo_table: Option<Box<namespace_b::TableInNestedNST>>,
|
||||
pub foo_enum: namespace_b::EnumInNestedNS,
|
||||
pub foo_struct: Option<namespace_b::StructInNestedNST>,
|
||||
}
|
||||
impl TableInFirstNST {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<TableInFirstNS<'b>> {
|
||||
let foo_table = self.foo_table.as_ref().map(|x|{
|
||||
x.pack(_fbb)
|
||||
});
|
||||
let foo_enum = self.foo_enum;
|
||||
let foo_struct_tmp = self.foo_struct.as_ref().map(|x| x.pack());
|
||||
let foo_struct = foo_struct_tmp.as_ref();
|
||||
TableInFirstNS::create(_fbb, &TableInFirstNSArgs{
|
||||
foo_table,
|
||||
foo_enum,
|
||||
foo_struct,
|
||||
})
|
||||
}
|
||||
}
|
||||
pub enum SecondTableInAOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
@@ -167,9 +204,7 @@ impl<'a> SecondTableInA<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
SecondTableInA {
|
||||
_tab: table,
|
||||
}
|
||||
SecondTableInA { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
@@ -180,6 +215,14 @@ impl<'a> SecondTableInA<'a> {
|
||||
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]
|
||||
@@ -242,6 +285,24 @@ impl std::fmt::Debug for SecondTableInA<'_> {
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct SecondTableInAT {
|
||||
pub refer_to_c: Option<Box<super::namespace_c::TableInCT>>,
|
||||
}
|
||||
impl SecondTableInAT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<SecondTableInA<'b>> {
|
||||
let refer_to_c = self.refer_to_c.as_ref().map(|x|{
|
||||
x.pack(_fbb)
|
||||
});
|
||||
SecondTableInA::create(_fbb, &SecondTableInAArgs{
|
||||
refer_to_c,
|
||||
})
|
||||
}
|
||||
}
|
||||
} // pub mod NamespaceA
|
||||
|
||||
#[allow(unused_imports, dead_code)]
|
||||
@@ -276,9 +337,7 @@ impl<'a> TableInC<'a> {
|
||||
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
TableInC {
|
||||
_tab: table,
|
||||
}
|
||||
TableInC { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
@@ -290,6 +349,18 @@ impl<'a> TableInC<'a> {
|
||||
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;
|
||||
|
||||
@@ -365,5 +436,28 @@ impl std::fmt::Debug for TableInC<'_> {
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct TableInCT {
|
||||
pub refer_to_a1: Option<Box<super::namespace_a::TableInFirstNST>>,
|
||||
pub refer_to_a2: Option<Box<super::namespace_a::SecondTableInAT>>,
|
||||
}
|
||||
impl TableInCT {
|
||||
pub fn pack<'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
||||
) -> flatbuffers::WIPOffset<TableInC<'b>> {
|
||||
let refer_to_a1 = self.refer_to_a1.as_ref().map(|x|{
|
||||
x.pack(_fbb)
|
||||
});
|
||||
let refer_to_a2 = self.refer_to_a2.as_ref().map(|x|{
|
||||
x.pack(_fbb)
|
||||
});
|
||||
TableInC::create(_fbb, &TableInCArgs{
|
||||
refer_to_a1,
|
||||
refer_to_a2,
|
||||
})
|
||||
}
|
||||
}
|
||||
} // pub mod NamespaceC
|
||||
|
||||
|
||||
Reference in New Issue
Block a user