summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCasper <casperneo@uchicago.edu>2021-01-22 13:07:32 -0500
committerGitHub <noreply@github.com>2021-01-22 13:07:32 -0500
commit1da0a2dfac4bd9a6876a7c39c4eea5eeefc36aa2 (patch)
treea48ac3f7455c980b05ca41d3e44d5e367b0260d2 /tests
parent796ed68faf434cac90f094a5fdf47137ba74e5a2 (diff)
downloadflatbuffers-1da0a2dfac4bd9a6876a7c39c4eea5eeefc36aa2.tar.gz
flatbuffers-1da0a2dfac4bd9a6876a7c39c4eea5eeefc36aa2.tar.bz2
flatbuffers-1da0a2dfac4bd9a6876a7c39c4eea5eeefc36aa2.zip
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>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/RustTest.sh39
-rw-r--r--tests/generate_code.bat4
-rwxr-xr-xtests/generate_code.sh4
-rw-r--r--tests/include_test/include_test1_generated.rs4
-rw-r--r--tests/include_test/sub/include_test2_generated.rs8
-rw-r--r--tests/monster_test_generated.rs1018
-rw-r--r--tests/namespace_test/namespace_test1_generated.rs50
-rw-r--r--tests/namespace_test/namespace_test2_generated.rs112
-rw-r--r--tests/optional_scalars_generated.rs203
-rw-r--r--tests/rust_usage_test/bin/flatbuffers_alloc_check.rs2
-rw-r--r--tests/rust_usage_test/bin/monster_example.rs2
-rw-r--r--tests/rust_usage_test/tests/integration_test.rs44
-rw-r--r--tests/rust_usage_test/tests/optional_scalars_test.rs10
13 files changed, 1416 insertions, 84 deletions
diff --git a/tests/RustTest.sh b/tests/RustTest.sh
index a74690af..7fa64926 100755
--- a/tests/RustTest.sh
+++ b/tests/RustTest.sh
@@ -21,33 +21,30 @@ if [[ "$1" == "mips-unknown-linux-gnu" ]]; then
export CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_RUNNER="qemu-mips -L /usr/mips-linux-gnu"
fi
+
+function check_test_result() {
+ if [[ $? == 0 ]]; then
+ echo OK: $1 passed.
+ else
+ echo KO: $1 failed.
+ exit 1
+ fi
+}
+
cd ./rust_usage_test
cargo test $TARGET_FLAG -- --quiet
-TEST_RESULT=$?
-if [[ $TEST_RESULT == 0 ]]; then
- echo "OK: Rust tests passed."
-else
- echo "KO: Rust tests failed."
- exit 1
-fi
+check_test_result "Rust tests"
+
cargo run $TARGET_FLAG --bin=flatbuffers_alloc_check
-TEST_RESULT=$?
-if [[ $TEST_RESULT == 0 ]]; then
- echo "OK: Rust heap alloc test passed."
-else
- echo "KO: Rust heap alloc test failed."
- exit 1
-fi
+check_test_result "Rust flatbuffers heap alloc test"
cargo run $TARGET_FLAG --bin=flexbuffers_alloc_check
-TEST_RESULT=$?
-if [[ $TEST_RESULT == 0 ]]; then
- echo "OK: Rust heap alloc test passed."
-else
- echo "KO: Rust heap alloc test failed."
- exit 1
-fi
+check_test_result "Rust flexbuffers heap alloc test"
+
+rustup component add clippy
+cargo clippy $TARGET_FLAG
+check_test_result "No Cargo clippy lints test"
cargo bench $TARGET_FLAG
diff --git a/tests/generate_code.bat b/tests/generate_code.bat
index 045e6883..7972d1c7 100644
--- a/tests/generate_code.bat
+++ b/tests/generate_code.bat
@@ -55,8 +55,8 @@ set TEST_NOINCL_FLAGS=%TEST_BASE_FLAGS% --no-includes
..\%buildtype%\flatc.exe --cpp %TEST_BASE_FLAGS% --cpp-ptr-type flatbuffers::unique_ptr native_type_test.fbs || goto FAIL
@rem Generate the optional scalar code for tests.
-..\%buildtype%\flatc.exe --java --kotlin --rust --lobster --ts optional_scalars.fbs || goto FAIL
-..\%buildtype%\flatc.exe --csharp --gen-object-api optional_scalars.fbs || goto FAIL
+..\%buildtype%\flatc.exe --java --kotlin --lobster --ts optional_scalars.fbs || goto FAIL
+..\%buildtype%\flatc.exe --csharp --rust --gen-object-api optional_scalars.fbs || goto FAIL
..\%buildtype%\flatc.exe %TEST_NOINCL_FLAGS% %TEST_CPP_FLAGS% --cpp optional_scalars.fbs || goto FAIL
@rem Generate the schema evolution tests
diff --git a/tests/generate_code.sh b/tests/generate_code.sh
index e0744623..f8229c49 100755
--- a/tests/generate_code.sh
+++ b/tests/generate_code.sh
@@ -53,8 +53,8 @@ $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS $TEST_CS_FLAGS $TEST_JS_TS_FLAGS -o namespace
../flatc --dart monster_extra.fbs
# Generate optional scalar code for tests.
-../flatc --java --kotlin --rust --lobster --ts optional_scalars.fbs
-../flatc --csharp --gen-object-api optional_scalars.fbs
+../flatc --java --kotlin --lobster --ts optional_scalars.fbs
+../flatc --csharp --rust --gen-object-api optional_scalars.fbs
../flatc $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS --cpp optional_scalars.fbs
# Generate the schema evolution tests
diff --git a/tests/include_test/include_test1_generated.rs b/tests/include_test/include_test1_generated.rs
index 23c0d3f4..4015a3c8 100644
--- a/tests/include_test/include_test1_generated.rs
+++ b/tests/include_test/include_test1_generated.rs
@@ -28,9 +28,7 @@ impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
impl<'a> TableA<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
- TableA {
- _tab: table,
- }
+ TableA { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
diff --git a/tests/include_test/sub/include_test2_generated.rs b/tests/include_test/sub/include_test2_generated.rs
index a0137b9c..9b3c7ee6 100644
--- a/tests/include_test/sub/include_test2_generated.rs
+++ b/tests/include_test/sub/include_test2_generated.rs
@@ -39,7 +39,7 @@ pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [
FromInclude::IncludeVal,
];
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct FromInclude(pub i64);
#[allow(non_upper_case_globals)]
@@ -111,7 +111,7 @@ impl<'a> flatbuffers::Verifiable for FromInclude {
impl flatbuffers::SimpleToVerifyInSlice for FromInclude {}
// struct Unused, aligned to 4
#[repr(transparent)]
-#[derive(Clone, Copy, PartialEq)]
+#[derive(Clone, Copy, PartialEq, Default)]
pub struct Unused(pub [u8; 4]);
impl std::fmt::Debug for Unused {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
@@ -221,9 +221,7 @@ impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
impl<'a> TableB<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
- TableB {
- _tab: table,
- }
+ TableB { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
diff --git a/tests/monster_test_generated.rs b/tests/monster_test_generated.rs
index 59c8f142..3f8714ba 100644
--- a/tests/monster_test_generated.rs
+++ b/tests/monster_test_generated.rs
@@ -44,9 +44,7 @@ impl<'a> InParentNamespace<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
- InParentNamespace {
- _tab: table,
- }
+ InParentNamespace { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
@@ -56,6 +54,10 @@ impl<'a> InParentNamespace<'a> {
builder.finish()
}
+ pub fn unpack(&self) -> InParentNamespaceT {
+ InParentNamespaceT {
+ }
+ }
}
impl flatbuffers::Verifiable for InParentNamespace<'_> {
@@ -104,6 +106,19 @@ impl std::fmt::Debug for InParentNamespace<'_> {
ds.finish()
}
}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct InParentNamespaceT {
+}
+impl InParentNamespaceT {
+ pub fn pack<'b>(
+ &self,
+ _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+ ) -> flatbuffers::WIPOffset<InParentNamespace<'b>> {
+ InParentNamespace::create(_fbb, &InParentNamespaceArgs{
+ })
+ }
+}
#[allow(unused_imports, dead_code)]
pub mod example_2 {
@@ -137,9 +152,7 @@ impl<'a> Monster<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
- Monster {
- _tab: table,
- }
+ Monster { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
@@ -149,6 +162,10 @@ impl<'a> Monster<'a> {
builder.finish()
}
+ pub fn unpack(&self) -> MonsterT {
+ MonsterT {
+ }
+ }
}
impl flatbuffers::Verifiable for Monster<'_> {
@@ -197,6 +214,19 @@ impl std::fmt::Debug for Monster<'_> {
ds.finish()
}
}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct MonsterT {
+}
+impl MonsterT {
+ pub fn pack<'b>(
+ &self,
+ _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+ ) -> flatbuffers::WIPOffset<Monster<'b>> {
+ Monster::create(_fbb, &MonsterArgs{
+ })
+ }
+}
} // pub mod Example2
#[allow(unused_imports, dead_code)]
@@ -214,6 +244,7 @@ pub mod example {
mod bitflags_color {
flatbuffers::bitflags::bitflags! {
/// Composite components of Monster color.
+ #[derive(Default)]
pub struct Color: u8 {
const Red = 1;
/// \brief color Green
@@ -280,7 +311,7 @@ pub const ENUM_VALUES_RACE: [Race; 4] = [
Race::Elf,
];
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct Race(pub i8);
#[allow(non_upper_case_globals)]
@@ -372,7 +403,7 @@ pub const ENUM_VALUES_ANY: [Any; 4] = [
Any::MyGame_Example2_Monster,
];
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct Any(pub u8);
#[allow(non_upper_case_globals)]
@@ -410,7 +441,6 @@ impl std::fmt::Debug for Any {
}
}
}
-pub struct AnyUnionTableOffset {}
impl<'a> flatbuffers::Follow<'a> for Any {
type Inner = Self;
#[inline]
@@ -452,6 +482,102 @@ impl<'a> flatbuffers::Verifiable for Any {
}
impl flatbuffers::SimpleToVerifyInSlice for Any {}
+pub struct AnyUnionTableOffset {}
+
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq)]
+pub enum AnyT {
+ NONE,
+ Monster(Box<MonsterT>),
+ TestSimpleTableWithEnum(Box<TestSimpleTableWithEnumT>),
+ MyGameExample2Monster(Box<super::example_2::MonsterT>),
+}
+impl Default for AnyT {
+ fn default() -> Self {
+ Self::NONE
+ }
+}
+impl AnyT {
+ fn any_type(&self) -> Any {
+ match self {
+ Self::NONE => Any::NONE,
+ Self::Monster(_) => Any::Monster,
+ Self::TestSimpleTableWithEnum(_) => Any::TestSimpleTableWithEnum,
+ Self::MyGameExample2Monster(_) => Any::MyGame_Example2_Monster,
+ }
+ }
+ pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
+ match self {
+ Self::NONE => None,
+ Self::Monster(v) => Some(v.pack(fbb).as_union_value()),
+ Self::TestSimpleTableWithEnum(v) => Some(v.pack(fbb).as_union_value()),
+ Self::MyGameExample2Monster(v) => Some(v.pack(fbb).as_union_value()),
+ }
+ }
+ /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
+ pub fn take_monster(&mut self) -> Option<Box<MonsterT>> {
+ if let Self::Monster(_) = self {
+ let v = std::mem::replace(self, Self::NONE);
+ if let Self::Monster(w) = v {
+ Some(w)
+ } else {
+ unreachable!()
+ }
+ } else {
+ None
+ }
+ }
+ /// If the union variant matches, return a reference to the MonsterT.
+ pub fn as_monster(&self) -> Option<&MonsterT> {
+ if let Self::Monster(v) = self { Some(v.as_ref()) } else { None }
+ }
+ /// If the union variant matches, return a mutable reference to the MonsterT.
+ pub fn as_monster_mut(&mut self) -> Option<&mut MonsterT> {
+ if let Self::Monster(v) = self { Some(v.as_mut()) } else { None }
+ }
+ /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE.
+ pub fn take_test_simple_table_with_enum(&mut self) -> Option<Box<TestSimpleTableWithEnumT>> {
+ if let Self::TestSimpleTableWithEnum(_) = self {
+ let v = std::mem::replace(self, Self::NONE);
+ if let Self::TestSimpleTableWithEnum(w) = v {
+ Some(w)
+ } else {
+ unreachable!()
+ }
+ } else {
+ None
+ }
+ }
+ /// If the union variant matches, return a reference to the TestSimpleTableWithEnumT.
+ pub fn as_test_simple_table_with_enum(&self) -> Option<&TestSimpleTableWithEnumT> {
+ if let Self::TestSimpleTableWithEnum(v) = self { Some(v.as_ref()) } else { None }
+ }
+ /// If the union variant matches, return a mutable reference to the TestSimpleTableWithEnumT.
+ pub fn as_test_simple_table_with_enum_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT> {
+ if let Self::TestSimpleTableWithEnum(v) = self { Some(v.as_mut()) } else { None }
+ }
+ /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE.
+ pub fn take_my_game_example_2_monster(&mut self) -> Option<Box<super::example_2::MonsterT>> {
+ if let Self::MyGameExample2Monster(_) = self {
+ let v = std::mem::replace(self, Self::NONE);
+ if let Self::MyGameExample2Monster(w) = v {
+ Some(w)
+ } else {
+ unreachable!()
+ }
+ } else {
+ None
+ }
+ }
+ /// If the union variant matches, return a reference to the super::example_2::MonsterT.
+ pub fn as_my_game_example_2_monster(&self) -> Option<&super::example_2::MonsterT> {
+ if let Self::MyGameExample2Monster(v) = self { Some(v.as_ref()) } else { None }
+ }
+ /// If the union variant matches, return a mutable reference to the super::example_2::MonsterT.
+ pub fn as_my_game_example_2_monster_mut(&mut self) -> Option<&mut super::example_2::MonsterT> {
+ if let Self::MyGameExample2Monster(v) = self { Some(v.as_mut()) } else { None }
+ }
+}
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MIN_ANY_UNIQUE_ALIASES: u8 = 0;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
@@ -465,7 +591,7 @@ pub const ENUM_VALUES_ANY_UNIQUE_ALIASES: [AnyUniqueAliases; 4] = [
AnyUniqueAliases::M2,
];
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct AnyUniqueAliases(pub u8);
#[allow(non_upper_case_globals)]
@@ -503,7 +629,6 @@ impl std::fmt::Debug for AnyUniqueAliases {
}
}
}
-pub struct AnyUniqueAliasesUnionTableOffset {}
impl<'a> flatbuffers::Follow<'a> for AnyUniqueAliases {
type Inner = Self;
#[inline]
@@ -545,6 +670,102 @@ impl<'a> flatbuffers::Verifiable for AnyUniqueAliases {
}
impl flatbuffers::SimpleToVerifyInSlice for AnyUniqueAliases {}
+pub struct AnyUniqueAliasesUnionTableOffset {}
+
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq)]
+pub enum AnyUniqueAliasesT {
+ NONE,
+ M(Box<MonsterT>),
+ TS(Box<TestSimpleTableWithEnumT>),
+ M2(Box<super::example_2::MonsterT>),
+}
+impl Default for AnyUniqueAliasesT {
+ fn default() -> Self {
+ Self::NONE
+ }
+}
+impl AnyUniqueAliasesT {
+ fn any_unique_aliases_type(&self) -> AnyUniqueAliases {
+ match self {
+ Self::NONE => AnyUniqueAliases::NONE,
+ Self::M(_) => AnyUniqueAliases::M,
+ Self::TS(_) => AnyUniqueAliases::TS,
+ Self::M2(_) => AnyUniqueAliases::M2,
+ }
+ }
+ pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
+ match self {
+ Self::NONE => None,
+ Self::M(v) => Some(v.pack(fbb).as_union_value()),
+ Self::TS(v) => Some(v.pack(fbb).as_union_value()),
+ Self::M2(v) => Some(v.pack(fbb).as_union_value()),
+ }
+ }
+ /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
+ pub fn take_m(&mut self) -> Option<Box<MonsterT>> {
+ if let Self::M(_) = self {
+ let v = std::mem::replace(self, Self::NONE);
+ if let Self::M(w) = v {
+ Some(w)
+ } else {
+ unreachable!()
+ }
+ } else {
+ None
+ }
+ }
+ /// If the union variant matches, return a reference to the MonsterT.
+ pub fn as_m(&self) -> Option<&MonsterT> {
+ if let Self::M(v) = self { Some(v.as_ref()) } else { None }
+ }
+ /// If the union variant matches, return a mutable reference to the MonsterT.
+ pub fn as_m_mut(&mut self) -> Option<&mut MonsterT> {
+ if let Self::M(v) = self { Some(v.as_mut()) } else { None }
+ }
+ /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE.
+ pub fn take_ts(&mut self) -> Option<Box<TestSimpleTableWithEnumT>> {
+ if let Self::TS(_) = self {
+ let v = std::mem::replace(self, Self::NONE);
+ if let Self::TS(w) = v {
+ Some(w)
+ } else {
+ unreachable!()
+ }
+ } else {
+ None
+ }
+ }
+ /// If the union variant matches, return a reference to the TestSimpleTableWithEnumT.
+ pub fn as_ts(&self) -> Option<&TestSimpleTableWithEnumT> {
+ if let Self::TS(v) = self { Some(v.as_ref()) } else { None }
+ }
+ /// If the union variant matches, return a mutable reference to the TestSimpleTableWithEnumT.
+ pub fn as_ts_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT> {
+ if let Self::TS(v) = self { Some(v.as_mut()) } else { None }
+ }
+ /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE.
+ pub fn take_m2(&mut self) -> Option<Box<super::example_2::MonsterT>> {
+ if let Self::M2(_) = self {
+ let v = std::mem::replace(self, Self::NONE);
+ if let Self::M2(w) = v {
+ Some(w)
+ } else {
+ unreachable!()
+ }
+ } else {
+ None
+ }
+ }
+ /// If the union variant matches, return a reference to the super::example_2::MonsterT.
+ pub fn as_m2(&self) -> Option<&super::example_2::MonsterT> {
+ if let Self::M2(v) = self { Some(v.as_ref()) } else { None }
+ }
+ /// If the union variant matches, return a mutable reference to the super::example_2::MonsterT.
+ pub fn as_m2_mut(&mut self) -> Option<&mut super::example_2::MonsterT> {
+ if let Self::M2(v) = self { Some(v.as_mut()) } else { None }
+ }
+}
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MIN_ANY_AMBIGUOUS_ALIASES: u8 = 0;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
@@ -558,7 +779,7 @@ pub const ENUM_VALUES_ANY_AMBIGUOUS_ALIASES: [AnyAmbiguousAliases; 4] = [
AnyAmbiguousAliases::M3,
];
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct AnyAmbiguousAliases(pub u8);
#[allow(non_upper_case_globals)]
@@ -596,7 +817,6 @@ impl std::fmt::Debug for AnyAmbiguousAliases {
}
}
}
-pub struct AnyAmbiguousAliasesUnionTableOffset {}
impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
type Inner = Self;
#[inline]
@@ -638,9 +858,105 @@ impl<'a> flatbuffers::Verifiable for AnyAmbiguousAliases {
}
impl flatbuffers::SimpleToVerifyInSlice for AnyAmbiguousAliases {}
+pub struct AnyAmbiguousAliasesUnionTableOffset {}
+
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq)]
+pub enum AnyAmbiguousAliasesT {
+ NONE,
+ M1(Box<MonsterT>),
+ M2(Box<MonsterT>),
+ M3(Box<MonsterT>),
+}
+impl Default for AnyAmbiguousAliasesT {
+ fn default() -> Self {
+ Self::NONE
+ }
+}
+impl AnyAmbiguousAliasesT {
+ fn any_ambiguous_aliases_type(&self) -> AnyAmbiguousAliases {
+ match self {
+ Self::NONE => AnyAmbiguousAliases::NONE,
+ Self::M1(_) => AnyAmbiguousAliases::M1,
+ Self::M2(_) => AnyAmbiguousAliases::M2,
+ Self::M3(_) => AnyAmbiguousAliases::M3,
+ }
+ }
+ pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
+ match self {
+ Self::NONE => None,
+ Self::M1(v) => Some(v.pack(fbb).as_union_value()),
+ Self::M2(v) => Some(v.pack(fbb).as_union_value()),
+ Self::M3(v) => Some(v.pack(fbb).as_union_value()),
+ }
+ }
+ /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
+ pub fn take_m1(&mut self) -> Option<Box<MonsterT>> {
+ if let Self::M1(_) = self {
+ let v = std::mem::replace(self, Self::NONE);
+ if let Self::M1(w) = v {
+ Some(w)
+ } else {
+ unreachable!()
+ }
+ } else {
+ None
+ }
+ }
+ /// If the union variant matches, return a reference to the MonsterT.
+ pub fn as_m1(&self) -> Option<&MonsterT> {
+ if let Self::M1(v) = self { Some(v.as_ref()) } else { None }
+ }
+ /// If the union variant matches, return a mutable reference to the MonsterT.
+ pub fn as_m1_mut(&mut self) -> Option<&mut MonsterT> {
+ if let Self::M1(v) = self { Some(v.as_mut()) } else { None }
+ }
+ /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
+ pub fn take_m2(&mut self) -> Option<Box<MonsterT>> {
+ if let Self::M2(_) = self {
+ let v = std::mem::replace(self, Self::NONE);
+ if let Self::M2(w) = v {
+ Some(w)
+ } else {
+ unreachable!()
+ }
+ } else {
+ None
+ }
+ }
+ /// If the union variant matches, return a reference to the MonsterT.
+ pub fn as_m2(&self) -> Option<&MonsterT> {
+ if let Self::M2(v) = self { Some(v.as_ref()) } else { None }
+ }
+ /// If the union variant matches, return a mutable reference to the MonsterT.
+ pub fn as_m2_mut(&mut self) -> Option<&mut MonsterT> {
+ if let Self::M2(v) = self { Some(v.as_mut()) } else { None }
+ }
+ /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
+ pub fn take_m3(&mut self) -> Option<Box<MonsterT>> {
+ if let Self::M3(_) = self {
+ let v = std::mem::replace(self, Self::NONE);
+ if let Self::M3(w) = v {
+ Some(w)
+ } else {
+ unreachable!()
+ }
+ } else {
+ None
+ }
+ }
+ /// If the union variant matches, return a reference to the MonsterT.
+ pub fn as_m3(&self) -> Option<&MonsterT> {
+ if let Self::M3(v) = self { Some(v.as_ref()) } else { None }
+ }
+ /// If the union variant matches, return a mutable reference to the MonsterT.
+ pub fn as_m3_mut(&mut self) -> Option<&mut MonsterT> {
+ if let Self::M3(v) = self { Some(v.as_mut()) } else { None }
+ }
+}
// struct Test, aligned to 2
#[repr(transparent)]
-#[derive(Clone, Copy, PartialEq)]
+#[derive(Clone, Copy, PartialEq, Default)]
pub struct Test(pub [u8; 4]);
impl std::fmt::Debug for Test {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
@@ -760,11 +1076,31 @@ impl Test {
}
}
+ pub fn unpack(&self) -> TestT {
+ TestT {
+ a: self.a(),
+ b: self.b(),
+ }
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct TestT {
+ pub a: i16,
+ pub b: i8,
+}
+impl TestT {
+ pub fn pack(&self) -> Test {
+ Test::new(
+ self.a,
+ self.b,
+ )
+ }
}
// struct Vec3, aligned to 8
#[repr(transparent)]
-#[derive(Clone, Copy, PartialEq)]
+#[derive(Clone, Copy, PartialEq, Default)]
pub struct Vec3(pub [u8; 32]);
impl std::fmt::Debug for Vec3 {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
@@ -973,11 +1309,43 @@ impl Vec3 {
self.0[26..26+4].copy_from_slice(&x.0)
}
+ pub fn unpack(&self) -> Vec3T {
+ Vec3T {
+ x: self.x(),
+ y: self.y(),
+ z: self.z(),
+ test1: self.test1(),
+ test2: self.test2(),
+ test3: self.test3().unpack(),
+ }
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct Vec3T {
+ pub x: f32,
+ pub y: f32,
+ pub z: f32,
+ pub test1: f64,
+ pub test2: Color,
+ pub test3: TestT,
+}
+impl Vec3T {
+ pub fn pack(&self) -> Vec3 {
+ Vec3::new(
+ self.x,
+ self.y,
+ self.z,
+ self.test1,
+ self.test2,
+ &self.test3.pack(),
+ )
+ }
}
// struct Ability, aligned to 4
#[repr(transparent)]
-#[derive(Clone, Copy, PartialEq)]
+#[derive(Clone, Copy, PartialEq, Default)]
pub struct Ability(pub [u8; 8]);
impl std::fmt::Debug for Ability {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
@@ -1107,6 +1475,26 @@ impl Ability {
}
}
+ pub fn unpack(&self) -> AbilityT {
+ AbilityT {
+ id: self.id(),
+ distance: self.distance(),
+ }
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct AbilityT {
+ pub id: u32,
+ pub distance: u32,
+}
+impl AbilityT {
+ pub fn pack(&self) -> Ability {
+ Ability::new(
+ self.id,
+ self.distance,
+ )
+ }
}
pub enum TestSimpleTableWithEnumOffset {}
@@ -1131,9 +1519,7 @@ impl<'a> TestSimpleTableWithEnum<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
- TestSimpleTableWithEnum {
- _tab: table,
- }
+ TestSimpleTableWithEnum { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
@@ -1144,6 +1530,12 @@ impl<'a> TestSimpleTableWithEnum<'a> {
builder.finish()
}
+ pub fn unpack(&self) -> TestSimpleTableWithEnumT {
+ let color = self.color();
+ TestSimpleTableWithEnumT {
+ color,
+ }
+ }
pub const VT_COLOR: flatbuffers::VOffsetT = 4;
#[inline]
@@ -1206,6 +1598,22 @@ impl std::fmt::Debug for TestSimpleTableWithEnum<'_> {
ds.finish()
}
}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct TestSimpleTableWithEnumT {
+ pub color: Color,
+}
+impl TestSimpleTableWithEnumT {
+ pub fn pack<'b>(
+ &self,
+ _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+ ) -> flatbuffers::WIPOffset<TestSimpleTableWithEnum<'b>> {
+ let color = self.color;
+ TestSimpleTableWithEnum::create(_fbb, &TestSimpleTableWithEnumArgs{
+ color,
+ })
+ }
+}
pub enum StatOffset {}
#[derive(Copy, Clone, PartialEq)]
@@ -1228,9 +1636,7 @@ impl<'a> Stat<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
- Stat {
- _tab: table,
- }
+ Stat { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
@@ -1243,6 +1649,18 @@ impl<'a> Stat<'a> {
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;
@@ -1341,6 +1759,30 @@ impl std::fmt::Debug for Stat<'_> {
ds.finish()
}
}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct StatT {
+ pub id: Option<String>,
+ pub val: i64,
+ pub count: u16,
+}
+impl StatT {
+ pub fn pack<'b>(
+ &self,
+ _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+ ) -> flatbuffers::WIPOffset<Stat<'b>> {
+ let id = self.id.as_ref().map(|x|{
+ _fbb.create_string(x)
+ });
+ let val = self.val;
+ let count = self.count;
+ Stat::create(_fbb, &StatArgs{
+ id,
+ val,
+ count,
+ })
+ }
+}
pub enum ReferrableOffset {}
#[derive(Copy, Clone, PartialEq)]
@@ -1363,9 +1805,7 @@ impl<'a> Referrable<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
- Referrable {
- _tab: table,
- }
+ Referrable { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
@@ -1376,6 +1816,12 @@ impl<'a> Referrable<'a> {
builder.finish()
}
+ pub fn unpack(&self) -> ReferrableT {
+ let id = self.id();
+ ReferrableT {
+ id,
+ }
+ }
pub const VT_ID: flatbuffers::VOffsetT = 4;
#[inline]
@@ -1448,6 +1894,22 @@ impl std::fmt::Debug for Referrable<'_> {
ds.finish()
}
}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct ReferrableT {
+ pub id: u64,
+}
+impl ReferrableT {
+ pub fn pack<'b>(
+ &self,
+ _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+ ) -> flatbuffers::WIPOffset<Referrable<'b>> {
+ let id = self.id;
+ Referrable::create(_fbb, &ReferrableArgs{
+ id,
+ })
+ }
+}
pub enum MonsterOffset {}
#[derive(Copy, Clone, PartialEq)]
@@ -1471,9 +1933,7 @@ impl<'a> Monster<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
- Monster {
- _tab: table,
- }
+ Monster { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
@@ -1533,6 +1993,209 @@ impl<'a> Monster<'a> {
builder.finish()
}
+ pub fn unpack(&self) -> MonsterT {
+ let pos = self.pos().map(|x| {
+ x.unpack()
+ });
+ let mana = self.mana();
+ let hp = self.hp();
+ let name = {
+ let x = self.name();
+ x.to_string()
+ };
+ let inventory = self.inventory().map(|x| {
+ x.to_vec()
+ });
+ let color = self.color();
+ let test = match self.test_type() {
+ Any::NONE => AnyT::NONE,
+ Any::Monster => AnyT::Monster(Box::new(
+ self.test_as_monster()
+ .expect("Invalid union table, expected `Any::Monster`.")
+ .unpack()
+ )),
+ Any::TestSimpleTableWithEnum => AnyT::TestSimpleTableWithEnum(Box::new(
+ self.test_as_test_simple_table_with_enum()
+ .expect("Invalid union table, expected `Any::TestSimpleTableWithEnum`.")
+ .unpack()
+ )),
+ Any::MyGame_Example2_Monster => AnyT::MyGameExample2Monster(Box::new(
+ self.test_as_my_game_example_2_monster()
+ .expect("Invalid union table, expected `Any::MyGame_Example2_Monster`.")
+ .unpack()
+ )),
+ _ => AnyT::NONE,
+ };
+ let test4 = self.test4().map(|x| {
+ x.iter().map(|t| t.unpack()).collect()
+ });
+ let testarrayofstring = self.testarrayofstring().map(|x| {
+ x.iter().map(|s| s.to_string()).collect()
+ });
+ let testarrayoftables = self.testarrayoftables().map(|x| {
+ x.iter().map(|t| t.unpack()).collect()
+ });
+ let enemy = self.enemy().map(|x| {
+ Box::new(x.unpack())
+ });
+ let testnestedflatbuffer = self.testnestedflatbuffer().map(|x| {
+ x.to_vec()
+ });
+ let testempty = self.testempty().map(|x| {
+ Box::new(x.unpack())
+ });
+ let testbool = self.testbool();
+ let testhashs32_fnv1 = self.testhashs32_fnv1();
+ let testhashu32_fnv1 = self.testhashu32_fnv1();
+ let testhashs64_fnv1 = self.testhashs64_fnv1();
+ let testhashu64_fnv1 = self.testhashu64_fnv1();
+ let testhashs32_fnv1a = self.testhashs32_fnv1a();
+ let testhashu32_fnv1a = self.testhashu32_fnv1a();
+ let testhashs64_fnv1a = self.testhashs64_fnv1a();
+ let testhashu64_fnv1a = self.testhashu64_fnv1a();
+ let testarrayofbools = self.testarrayofbools().map(|x| {
+ x.to_vec()
+ });
+ let testf = self.testf();
+ let testf2 = self.testf2();
+ let testf3 = self.testf3();
+ let testarrayofstring2 = self.testarrayofstring2().map(|x| {
+ x.iter().map(|s| s.to_string()).collect()
+ });
+ let testarrayofsortedstruct = self.testarrayofsortedstruct().map(|x| {
+ x.iter().map(|t| t.unpack()).collect()
+ });
+ let flex = self.flex().map(|x| {
+ x.to_vec()
+ });
+ let test5 = self.test5().map(|x| {
+ x.iter().map(|t| t.unpack()).collect()
+ });
+ let vector_of_longs = self.vector_of_longs().map(|x| {
+ x.into_iter().collect()
+ });
+ let vector_of_doubles = self.vector_of_doubles().map(|x| {
+ x.into_iter().collect()
+ });
+ let parent_namespace_test = self.parent_namespace_test().map(|x| {
+ Box::new(x.unpack())
+ });
+ let vector_of_referrables = self.vector_of_referrables().map(|x| {
+ x.iter().map(|t| t.unpack()).collect()
+ });
+ let single_weak_reference = self.single_weak_reference();
+ let vector_of_weak_references = self.vector_of_weak_references().map(|x| {
+ x.into_iter().collect()
+ });
+ let vector_of_strong_referrables = self.vector_of_strong_referrables().map(|x| {
+ x.iter().map(|t| t.unpack()).collect()
+ });
+ let co_owning_reference = self.co_owning_reference();
+ let vector_of_co_owning_references = self.vector_of_co_owning_references().map(|x| {
+ x.into_iter().collect()
+ });
+ let non_owning_reference = self.non_owning_reference();
+ let vector_of_non_owning_references = self.vector_of_non_owning_references().map(|x| {
+ x.into_iter().collect()
+ });
+ let any_unique = match self.any_unique_type() {
+ AnyUniqueAliases::NONE => AnyUniqueAliasesT::NONE,
+ AnyUniqueAliases::M => AnyUniqueAliasesT::M(Box::new(
+ self.any_unique_as_m()
+ .expect("Invalid union table, expected `AnyUniqueAliases::M`.")
+ .unpack()
+ )),
+ AnyUniqueAliases::TS => AnyUniqueAliasesT::TS(Box::new(
+ self.any_unique_as_ts()
+ .expect("Invalid union table, expected `AnyUniqueAliases::TS`.")
+ .unpack()
+ )),
+ AnyUniqueAliases::M2 => AnyUniqueAliasesT::M2(Box::new(
+ self.any_unique_as_m2()
+ .expect("Invalid union table, expected `AnyUniqueAliases::M2`.")
+ .unpack()
+ )),
+ _ => AnyUniqueAliasesT::NONE,
+ };
+ let any_ambiguous = match self.any_ambiguous_type() {
+ AnyAmbiguousAliases::NONE => AnyAmbiguousAliasesT::NONE,
+ AnyAmbiguousAliases::M1 => AnyAmbiguousAliasesT::M1(Box::new(
+ self.any_ambiguous_as_m1()
+ .expect("Invalid union table, expected `AnyAmbiguousAliases::M1`.")
+ .unpack()
+ )),
+ AnyAmbiguousAliases::M2 => AnyAmbiguousAliasesT::M2(Box::new(
+ self.any_ambiguous_as_m2()
+ .expect("Invalid union table, expected `AnyAmbiguousAliases::M2`.")
+ .unpack()
+ )),
+ AnyAmbiguousAliases::M3 => AnyAmbiguousAliasesT::M3(Box::new(
+ self.any_ambiguous_as_m3()
+ .expect("Invalid union table, expected `AnyAmbiguousAliases::M3`.")
+ .unpack()
+ )),
+ _ => AnyAmbiguousAliasesT::NONE,
+ };
+ let vector_of_enums = self.vector_of_enums().map(|x| {
+ x.into_iter().collect()
+ });
+ let signed_enum = self.signed_enum();
+ let testrequirednestedflatbuffer = self.testrequirednestedflatbuffer().map(|x| {
+ x.to_vec()
+ });
+ let scalar_key_sorted_tables = self.scalar_key_sorted_tables().map(|x| {
+ x.iter().map(|t| t.unpack()).collect()
+ });
+ MonsterT {
+ pos,
+ mana,
+ hp,
+ name,
+ inventory,
+ color,
+ test,
+ test4,
+ testarrayofstring,
+ testarrayoftables,
+ enemy,
+ testnestedflatbuffer,
+ testempty,
+ testbool,
+ testhashs32_fnv1,
+ testhashu32_fnv1,
+ testhashs64_fnv1,
+ testhashu64_fnv1,
+ testhashs32_fnv1a,
+ testhashu32_fnv1a,
+ testhashs64_fnv1a,
+ testhashu64_fnv1a,
+ testarrayofbools,
+ testf,
+ testf2,
+ testf3,
+ testarrayofstring2,
+ testarrayofsortedstruct,
+ flex,
+ test5,
+ vector_of_longs,
+ vector_of_doubles,
+ parent_namespace_test,
+ vector_of_referrables,
+ single_weak_reference,
+ vector_of_weak_references,
+ vector_of_strong_referrables,
+ co_owning_reference,
+ vector_of_co_owning_references,
+ non_owning_reference,
+ vector_of_non_owning_references,
+ any_unique,
+ any_ambiguous,
+ vector_of_enums,
+ signed_enum,
+ testrequirednestedflatbuffer,
+ scalar_key_sorted_tables,
+ }
+ }
pub const VT_POS: flatbuffers::VOffsetT = 4;
pub const VT_MANA: flatbuffers::VOffsetT = 6;
pub const VT_HP: flatbuffers::VOffsetT = 8;
@@ -2443,6 +3106,216 @@ impl std::fmt::Debug for Monster<'_> {
ds.finish()
}
}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct MonsterT {
+ pub pos: Option<Vec3T>,
+ pub mana: i16,
+ pub hp: i16,
+ pub name: String,
+ pub inventory: Option<Vec<u8>>,
+ pub color: Color,
+ pub test: AnyT,
+ pub test4: Option<Vec<TestT>>,
+ pub testarrayofstring: Option<Vec<String>>,
+ pub testarrayoftables: Option<Vec<MonsterT>>,
+ pub enemy: Option<Box<MonsterT>>,
+ pub testnestedflatbuffer: Option<Vec<u8>>,
+ pub testempty: Option<Box<StatT>>,
+ pub testbool: bool,
+ pub testhashs32_fnv1: i32,
+ pub testhashu32_fnv1: u32,
+ pub testhashs64_fnv1: i64,
+ pub testhashu64_fnv1: u64,
+ pub testhashs32_fnv1a: i32,
+ pub testhashu32_fnv1a: u32,
+ pub testhashs64_fnv1a: i64,
+ pub testhashu64_fnv1a: u64,
+ pub testarrayofbools: Option<Vec<bool>>,
+ pub testf: f32,
+ pub testf2: f32,
+ pub testf3: f32,
+ pub testarrayofstring2: Option<Vec<String>>,
+ pub testarrayofsortedstruct: Option<Vec<AbilityT>>,
+ pub flex: Option<Vec<u8>>,
+ pub test5: Option<Vec<TestT>>,
+ pub vector_of_longs: Option<Vec<i64>>,
+ pub vector_of_doubles: Option<Vec<f64>>,
+ pub parent_namespace_test: Option<Box<super::InParentNamespaceT>>,
+ pub vector_of_referrables: Option<Vec<ReferrableT>>,
+ pub single_weak_reference: u64,
+ pub vector_of_weak_references: Option<Vec<u64>>,
+ pub vector_of_strong_referrables: Option<Vec<ReferrableT>>,
+ pub co_owning_reference: u64,
+ pub vector_of_co_owning_references: Option<Vec<u64>>,
+ pub non_owning_reference: u64,
+ pub vector_of_non_owning_references: Option<Vec<u64>>,
+ pub any_unique: AnyUniqueAliasesT,
+ pub any_ambiguous: AnyAmbiguousAliasesT,
+ pub vector_of_enums: Option<Vec<Color>>,
+ pub signed_enum: Race,
+ pub testrequirednestedflatbuffer: Option<Vec<u8>>,
+ pub scalar_key_sorted_tables: Option<Vec<StatT>>,
+}
+impl MonsterT {
+ pub fn pack<'b>(
+ &self,
+ _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+ ) -> flatbuffers::WIPOffset<Monster<'b>> {
+ let pos_tmp = self.pos.as_ref().map(|x| x.pack());
+ let pos = pos_tmp.as_ref();
+ let mana = self.mana;
+ let hp = self.hp;
+ let name = Some({
+ let x = &self.name;
+ _fbb.create_string(x)
+ });
+ let inventory = self.inventory.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let color = self.color;
+ let test_type = self.test.any_type();
+ let test = self.test.pack(_fbb);
+ let test4 = self.test4.as_ref().map(|x|{
+ let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
+ });
+ let testarrayofstring = self.testarrayofstring.as_ref().map(|x|{
+ let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();_fbb.create_vector_of_strings(&w)
+ });
+ let testarrayoftables = self.testarrayoftables.as_ref().map(|x|{
+ let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
+ });
+ let enemy = self.enemy.as_ref().map(|x|{
+ x.pack(_fbb)
+ });
+ let testnestedflatbuffer = self.testnestedflatbuffer.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let testempty = self.testempty.as_ref().map(|x|{
+ x.pack(_fbb)
+ });
+ let testbool = self.testbool;
+ let testhashs32_fnv1 = self.testhashs32_fnv1;
+ let testhashu32_fnv1 = self.testhashu32_fnv1;
+ let testhashs64_fnv1 = self.testhashs64_fnv1;
+ let testhashu64_fnv1 = self.testhashu64_fnv1;
+ let testhashs32_fnv1a = self.testhashs32_fnv1a;
+ let testhashu32_fnv1a = self.testhashu32_fnv1a;
+ let testhashs64_fnv1a = self.testhashs64_fnv1a;
+ let testhashu64_fnv1a = self.testhashu64_fnv1a;
+ let testarrayofbools = self.testarrayofbools.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let testf = self.testf;
+ let testf2 = self.testf2;
+ let testf3 = self.testf3;
+ let testarrayofstring2 = self.testarrayofstring2.as_ref().map(|x|{
+ let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();_fbb.create_vector_of_strings(&w)
+ });
+ let testarrayofsortedstruct = self.testarrayofsortedstruct.as_ref().map(|x|{
+ let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
+ });
+ let flex = self.flex.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let test5 = self.test5.as_ref().map(|x|{
+ let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
+ });
+ let vector_of_longs = self.vector_of_longs.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let vector_of_doubles = self.vector_of_doubles.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let parent_namespace_test = self.parent_namespace_test.as_ref().map(|x|{
+ x.pack(_fbb)
+ });
+ let vector_of_referrables = self.vector_of_referrables.as_ref().map(|x|{
+ let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
+ });
+ let single_weak_reference = self.single_weak_reference;
+ let vector_of_weak_references = self.vector_of_weak_references.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let vector_of_strong_referrables = self.vector_of_strong_referrables.as_ref().map(|x|{
+ let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
+ });
+ let co_owning_reference = self.co_owning_reference;
+ let vector_of_co_owning_references = self.vector_of_co_owning_references.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let non_owning_reference = self.non_owning_reference;
+ let vector_of_non_owning_references = self.vector_of_non_owning_references.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let any_unique_type = self.any_unique.any_unique_aliases_type();
+ let any_unique = self.any_unique.pack(_fbb);
+ let any_ambiguous_type = self.any_ambiguous.any_ambiguous_aliases_type();
+ let any_ambiguous = self.any_ambiguous.pack(_fbb);
+ let vector_of_enums = self.vector_of_enums.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let signed_enum = self.signed_enum;
+ let testrequirednestedflatbuffer = self.testrequirednestedflatbuffer.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let scalar_key_sorted_tables = self.scalar_key_sorted_tables.as_ref().map(|x|{
+ let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
+ });
+ Monster::create(_fbb, &MonsterArgs{
+ pos,
+ mana,
+ hp,
+ name,
+ inventory,
+ color,
+ test_type,
+ test,
+ test4,
+ testarrayofstring,
+ testarrayoftables,
+ enemy,
+ testnestedflatbuffer,
+ testempty,
+ testbool,
+ testhashs32_fnv1,
+ testhashu32_fnv1,
+ testhashs64_fnv1,
+ testhashu64_fnv1,
+ testhashs32_fnv1a,
+ testhashu32_fnv1a,
+ testhashs64_fnv1a,
+ testhashu64_fnv1a,
+ testarrayofbools,
+ testf,
+ testf2,
+ testf3,
+ testarrayofstring2,
+ testarrayofsortedstruct,
+ flex,
+ test5,
+ vector_of_longs,
+ vector_of_doubles,
+ parent_namespace_test,
+ vector_of_referrables,
+ single_weak_reference,
+ vector_of_weak_references,
+ vector_of_strong_referrables,
+ co_owning_reference,
+ vector_of_co_owning_references,
+ non_owning_reference,
+ vector_of_non_owning_references,
+ any_unique_type,
+ any_unique,
+ any_ambiguous_type,
+ any_ambiguous,
+ vector_of_enums,
+ signed_enum,
+ testrequirednestedflatbuffer,
+ scalar_key_sorted_tables,
+ })
+ }
+}
pub enum TypeAliasesOffset {}
#[derive(Copy, Clone, PartialEq)]
@@ -2465,9 +3338,7 @@ impl<'a> TypeAliases<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
- TypeAliases {
- _tab: table,
- }
+ TypeAliases { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
@@ -2489,6 +3360,38 @@ impl<'a> TypeAliases<'a> {
builder.finish()
}
+ pub fn unpack(&self) -> TypeAliasesT {
+ let i8_ = self.i8_();
+ let u8_ = self.u8_();
+ let i16_ = self.i16_();
+ let u16_ = self.u16_();
+ let i32_ = self.i32_();
+ let u32_ = self.u32_();
+ let i64_ = self.i64_();
+ let u64_ = self.u64_();
+ let f32_ = self.f32_();
+ let f64_ = self.f64_();
+ let v8 = self.v8().map(|x| {
+ x.to_vec()
+ });
+ let vf64 = self.vf64().map(|x| {
+ x.into_iter().collect()
+ });
+ TypeAliasesT {
+ i8_,
+ u8_,
+ i16_,
+ u16_,
+ i32_,
+ u32_,
+ i64_,
+ u64_,
+ f32_,
+ f64_,
+ v8,
+ vf64,
+ }
+ }
pub const VT_I8_: flatbuffers::VOffsetT = 4;
pub const VT_U8_: flatbuffers::VOffsetT = 6;
pub const VT_I16_: flatbuffers::VOffsetT = 8;
@@ -2694,6 +3597,59 @@ impl std::fmt::Debug for TypeAliases<'_> {
ds.finish()
}
}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct TypeAliasesT {
+ pub i8_: i8,
+ pub u8_: u8,
+ pub i16_: i16,
+ pub u16_: u16,
+ pub i32_: i32,
+ pub u32_: u32,
+ pub i64_: i64,
+ pub u64_: u64,
+ pub f32_: f32,
+ pub f64_: f64,
+ pub v8: Option<Vec<i8>>,
+ pub vf64: Option<Vec<f64>>,
+}
+impl TypeAliasesT {
+ pub fn pack<'b>(
+ &self,
+ _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+ ) -> flatbuffers::WIPOffset<TypeAliases<'b>> {
+ let i8_ = self.i8_;
+ let u8_ = self.u8_;
+ let i16_ = self.i16_;
+ let u16_ = self.u16_;
+ let i32_ = self.i32_;
+ let u32_ = self.u32_;
+ let i64_ = self.i64_;
+ let u64_ = self.u64_;
+ let f32_ = self.f32_;
+ let f64_ = self.f64_;
+ let v8 = self.v8.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ let vf64 = self.vf64.as_ref().map(|x|{
+ _fbb.create_vector(x)
+ });
+ TypeAliases::create(_fbb, &TypeAliasesArgs{
+ i8_,
+ u8_,
+ i16_,
+ u16_,
+ i32_,
+ u32_,
+ i64_,
+ u64_,
+ f32_,
+ f64_,
+ v8,
+ vf64,
+ })
+ }
+}
#[inline]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
diff --git a/tests/namespace_test/namespace_test1_generated.rs b/tests/namespace_test/namespace_test1_generated.rs
index e3a58b61..516c9b88 100644
--- a/tests/namespace_test/namespace_test1_generated.rs
+++ b/tests/namespace_test/namespace_test1_generated.rs
@@ -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
diff --git a/tests/namespace_test/namespace_test2_generated.rs b/tests/namespace_test/namespace_test2_generated.rs
index 490dd6b9..a774dbfc 100644
--- a/tests/namespace_test/namespace_test2_generated.rs
+++ b/tests/namespace_test/namespace_test2_generated.rs
@@ -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
diff --git a/tests/optional_scalars_generated.rs b/tests/optional_scalars_generated.rs
index 702df823..73ebee30 100644
--- a/tests/optional_scalars_generated.rs
+++ b/tests/optional_scalars_generated.rs
@@ -30,7 +30,7 @@ pub const ENUM_VALUES_OPTIONAL_BYTE: [OptionalByte; 3] = [
OptionalByte::Two,
];
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct OptionalByte(pub i8);
#[allow(non_upper_case_globals)]
@@ -124,9 +124,7 @@ impl<'a> flatbuffers::Follow<'a> for ScalarStuff<'a> {
impl<'a> ScalarStuff<'a> {
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
- ScalarStuff {
- _tab: table,
- }
+ ScalarStuff { _tab: table }
}
#[allow(unused_mut)]
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
@@ -172,6 +170,82 @@ impl<'a> ScalarStuff<'a> {
builder.finish()
}
+ pub fn unpack(&self) -> ScalarStuffT {
+ let just_i8 = self.just_i8();
+ let maybe_i8 = self.maybe_i8();
+ let default_i8 = self.default_i8();
+ let just_u8 = self.just_u8();
+ let maybe_u8 = self.maybe_u8();
+ let default_u8 = self.default_u8();
+ let just_i16 = self.just_i16();
+ let maybe_i16 = self.maybe_i16();
+ let default_i16 = self.default_i16();
+ let just_u16 = self.just_u16();
+ let maybe_u16 = self.maybe_u16();
+ let default_u16 = self.default_u16();
+ let just_i32 = self.just_i32();
+ let maybe_i32 = self.maybe_i32();
+ let default_i32 = self.default_i32();
+ let just_u32 = self.just_u32();
+ let maybe_u32 = self.maybe_u32();
+ let default_u32 = self.default_u32();
+ let just_i64 = self.just_i64();
+ let maybe_i64 = self.maybe_i64();
+ let default_i64 = self.default_i64();
+ let just_u64 = self.just_u64();
+ let maybe_u64 = self.maybe_u64();
+ let default_u64 = self.default_u64();
+ let just_f32 = self.just_f32();
+ let maybe_f32 = self.maybe_f32();
+ let default_f32 = self.default_f32();
+ let just_f64 = self.just_f64();
+ let maybe_f64 = self.maybe_f64();
+ let default_f64 = self.default_f64();
+ let just_bool = self.just_bool();
+ let maybe_bool = self.maybe_bool();
+ let default_bool = self.default_bool();
+ let just_enum = self.just_enum();
+ let maybe_enum = self.maybe_enum();
+ let default_enum = self.default_enum();
+ ScalarStuffT {
+ just_i8,
+ maybe_i8,
+ default_i8,
+ just_u8,
+ maybe_u8,
+ default_u8,
+ just_i16,
+ maybe_i16,
+ default_i16,
+ just_u16,
+ maybe_u16,
+ default_u16,
+ just_i32,
+ maybe_i32,
+ default_i32,
+ just_u32,
+ maybe_u32,
+ default_u32,
+ just_i64,
+ maybe_i64,
+ default_i64,
+ just_u64,
+ maybe_u64,
+ default_u64,
+ just_f32,
+ maybe_f32,
+ default_f32,
+ just_f64,
+ maybe_f64,
+ default_f64,
+ just_bool,
+ maybe_bool,
+ default_bool,
+ just_enum,
+ maybe_enum,
+ default_enum,
+ }
+ }
pub const VT_JUST_I8: flatbuffers::VOffsetT = 4;
pub const VT_MAYBE_I8: flatbuffers::VOffsetT = 6;
pub const VT_DEFAULT_I8: flatbuffers::VOffsetT = 8;
@@ -689,6 +763,127 @@ impl std::fmt::Debug for ScalarStuff<'_> {
ds.finish()
}
}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct ScalarStuffT {
+ pub just_i8: i8,
+ pub maybe_i8: Option<i8>,
+ pub default_i8: i8,
+ pub just_u8: u8,
+ pub maybe_u8: Option<u8>,
+ pub default_u8: u8,
+ pub just_i16: i16,
+ pub maybe_i16: Option<i16>,
+ pub default_i16: i16,
+ pub just_u16: u16,
+ pub maybe_u16: Option<u16>,
+ pub default_u16: u16,
+ pub just_i32: i32,
+ pub maybe_i32: Option<i32>,
+ pub default_i32: i32,
+ pub just_u32: u32,
+ pub maybe_u32: Option<u32>,
+ pub default_u32: u32,
+ pub just_i64: i64,
+ pub maybe_i64: Option<i64>,
+ pub default_i64: i64,
+ pub just_u64: u64,
+ pub maybe_u64: Option<u64>,
+ pub default_u64: u64,
+ pub just_f32: f32,
+ pub maybe_f32: Option<f32>,
+ pub default_f32: f32,
+ pub just_f64: f64,
+ pub maybe_f64: Option<f64>,
+ pub default_f64: f64,
+ pub just_bool: bool,
+ pub maybe_bool: Option<bool>,
+ pub default_bool: bool,
+ pub just_enum: OptionalByte,
+ pub maybe_enum: Option<OptionalByte>,
+ pub default_enum: OptionalByte,
+}
+impl ScalarStuffT {
+ pub fn pack<'b>(
+ &self,
+ _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+ ) -> flatbuffers::WIPOffset<ScalarStuff<'b>> {
+ let just_i8 = self.just_i8;
+ let maybe_i8 = self.maybe_i8;
+ let default_i8 = self.default_i8;
+ let just_u8 = self.just_u8;
+ let maybe_u8 = self.maybe_u8;
+ let default_u8 = self.default_u8;
+ let just_i16 = self.just_i16;
+ let maybe_i16 = self.maybe_i16;
+ let default_i16 = self.default_i16;
+ let just_u16 = self.just_u16;
+ let maybe_u16 = self.maybe_u16;
+ let default_u16 = self.default_u16;
+ let just_i32 = self.just_i32;
+ let maybe_i32 = self.maybe_i32;
+ let default_i32 = self.default_i32;
+ let just_u32 = self.just_u32;
+ let maybe_u32 = self.maybe_u32;
+ let default_u32 = self.default_u32;
+ let just_i64 = self.just_i64;
+ let maybe_i64 = self.maybe_i64;
+ let default_i64 = self.default_i64;
+ let just_u64 = self.just_u64;
+ let maybe_u64 = self.maybe_u64;
+ let default_u64 = self.default_u64;
+ let just_f32 = self.just_f32;
+ let maybe_f32 = self.maybe_f32;
+ let default_f32 = self.default_f32;
+ let just_f64 = self.just_f64;
+ let maybe_f64 = self.maybe_f64;
+ let default_f64 = self.default_f64;
+ let just_bool = self.just_bool;
+ let maybe_bool = self.maybe_bool;
+ let default_bool = self.default_bool;
+ let just_enum = self.just_enum;
+ let maybe_enum = self.maybe_enum;
+ let default_enum = self.default_enum;
+ ScalarStuff::create(_fbb, &ScalarStuffArgs{
+ just_i8,
+ maybe_i8,
+ default_i8,
+ just_u8,
+ maybe_u8,
+ default_u8,
+ just_i16,
+ maybe_i16,
+ default_i16,
+ just_u16,
+ maybe_u16,
+ default_u16,
+ just_i32,
+ maybe_i32,
+ default_i32,
+ just_u32,
+ maybe_u32,
+ default_u32,
+ just_i64,
+ maybe_i64,
+ default_i64,
+ just_u64,
+ maybe_u64,
+ default_u64,
+ just_f32,
+ maybe_f32,
+ default_f32,
+ just_f64,
+ maybe_f64,
+ default_f64,
+ just_bool,
+ maybe_bool,
+ default_bool,
+ just_enum,
+ maybe_enum,
+ default_enum,
+ })
+ }
+}
#[inline]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_root_as_scalar_stuff<'a>(buf: &'a [u8]) -> ScalarStuff<'a> {
diff --git a/tests/rust_usage_test/bin/flatbuffers_alloc_check.rs b/tests/rust_usage_test/bin/flatbuffers_alloc_check.rs
index 7cf2db5c..84abd1e0 100644
--- a/tests/rust_usage_test/bin/flatbuffers_alloc_check.rs
+++ b/tests/rust_usage_test/bin/flatbuffers_alloc_check.rs
@@ -36,7 +36,7 @@ pub mod include_test1_generated;
#[path = "../../include_test/sub/include_test2_generated.rs"]
pub mod include_test2_generated;
-#[allow(dead_code, unused_imports)]
+#[allow(dead_code, unused_imports, clippy::approx_constant)]
#[path = "../../monster_test_generated.rs"]
mod monster_test_generated;
pub use monster_test_generated::my_game;
diff --git a/tests/rust_usage_test/bin/monster_example.rs b/tests/rust_usage_test/bin/monster_example.rs
index a3c4300d..2e3c7ac6 100644
--- a/tests/rust_usage_test/bin/monster_example.rs
+++ b/tests/rust_usage_test/bin/monster_example.rs
@@ -8,7 +8,7 @@ pub mod include_test1_generated;
#[path = "../../include_test/sub/include_test2_generated.rs"]
pub mod include_test2_generated;
-#[allow(dead_code, unused_imports)]
+#[allow(dead_code, unused_imports, clippy::approx_constant)]
#[path = "../../monster_test_generated.rs"]
mod monster_test_generated;
pub use monster_test_generated::my_game;
diff --git a/tests/rust_usage_test/tests/integration_test.rs b/tests/rust_usage_test/tests/integration_test.rs
index a3071280..c5a0a56d 100644
--- a/tests/rust_usage_test/tests/integration_test.rs
+++ b/tests/rust_usage_test/tests/integration_test.rs
@@ -227,6 +227,50 @@ fn serialized_example_is_accessible_and_correct(bytes: &[u8], identifier_require
Ok(())
}
+#[test]
+fn test_object_api_reads_correctly() -> Result<(), &'static str>{
+ let mut fbb = flatbuffers::FlatBufferBuilder::new();
+ create_serialized_example_with_library_code(&mut fbb);
+
+ let m = my_game::example::root_as_monster(fbb.finished_data()).unwrap().unpack();
+
+ check_eq!(m.hp, 80)?;
+ check_eq!(m.mana, 150)?;
+ check_eq!(m.name, "MyMonster")?;
+
+ let pos = m.pos.as_ref().unwrap();
+ check_eq!(pos.x, 1.0f32)?;
+ check_eq!(pos.y, 2.0f32)?;
+ check_eq!(pos.z, 3.0f32)?;
+ check_eq!(pos.test1, 3.0f64)?;
+ check_eq!(pos.test2, my_game::example::Color::Green)?;
+
+ let pos_test3 = &pos.test3;
+ check_eq!(pos_test3.a, 5i16)?;
+ check_eq!(pos_test3.b, 6i8)?;
+
+ let monster2 = m.test.as_monster().unwrap();
+ check_eq!(monster2.name, "Fred")?;
+
+ let inv = m.inventory.as_ref().unwrap();
+ check_eq!(inv.len(), 5)?;
+ check_eq!(inv.iter().sum::<u8>(), 10u8)?;
+ check_eq!(inv.iter().rev().sum::<u8>(), 10u8)?;
+
+ let test4 = m.test4.as_ref().unwrap();
+ check_eq!(test4.len(), 2)?;
+ check_eq!(test4[0].a as i32 + test4[0].b as i32 +
+ test4[1].a as i32 + test4[1].b as i32, 100)?;
+
+ let testarrayofstring = m.testarrayofstring.as_ref().unwrap();
+ check_eq!(testarrayofstring.len(), 2)?;
+ check_eq!(testarrayofstring[0], "test1")?;
+ check_eq!(testarrayofstring[1], "test2")?;
+ Ok(())
+}
+
+
+
// Disabled due to Windows CI limitations.
// #[test]
// fn builder_initializes_with_maximum_buffer_size() {
diff --git a/tests/rust_usage_test/tests/optional_scalars_test.rs b/tests/rust_usage_test/tests/optional_scalars_test.rs
index 5a662414..32e93725 100644
--- a/tests/rust_usage_test/tests/optional_scalars_test.rs
+++ b/tests/rust_usage_test/tests/optional_scalars_test.rs
@@ -37,6 +37,16 @@ macro_rules! make_test {
assert_eq!(s.$just(), $zero);
assert_eq!(s.$default(), $fortytwo);
assert_eq!(s.$maybe(), None);
+
+ // Same for object API
+ let s = flatbuffers::root::<ScalarStuff>(builder.finished_data()).unwrap().unpack();
+ assert_eq!(s.$just, $five);
+ assert_eq!(s.$default, $five);
+ assert_eq!(s.$maybe, Some($five));
+ let s = flatbuffers::root::<ScalarStuff>(&[0; 8]).unwrap().unpack();
+ assert_eq!(s.$just, $zero);
+ assert_eq!(s.$default, $fortytwo);
+ assert_eq!(s.$maybe, None);
}
};
}