[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
// automatically generated by the FlatBuffers compiler, do not modify
|
2022-08-10 13:15:35 +00:00
|
|
|
// @generated
|
2022-04-27 01:40:03 +00:00
|
|
|
extern crate alloc;
|
2021-07-22 23:02:28 +00:00
|
|
|
extern crate flatbuffers;
|
2022-04-27 01:40:03 +00:00
|
|
|
use alloc::boxed::Box;
|
|
|
|
use alloc::string::{String, ToString};
|
|
|
|
use alloc::vec::Vec;
|
|
|
|
use core::mem;
|
|
|
|
use core::cmp::Ordering;
|
2021-04-16 15:15:59 +00:00
|
|
|
use self::flatbuffers::{EndianScalar, Follow};
|
2021-07-22 23:02:28 +00:00
|
|
|
use super::*;
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
pub enum TableAOffset {}
|
2020-10-29 19:57:29 +00:00
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
|
|
|
|
pub struct TableA<'a> {
|
|
|
|
pub _tab: flatbuffers::Table<'a>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
|
2021-08-23 22:53:10 +00:00
|
|
|
type Inner = TableA<'a>;
|
|
|
|
#[inline]
|
2022-09-29 13:58:49 +00:00
|
|
|
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
|
|
|
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
2021-08-23 22:53:10 +00:00
|
|
|
}
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> TableA<'a> {
|
2021-08-23 22:53:10 +00:00
|
|
|
pub const VT_B: flatbuffers::VOffsetT = 4;
|
2021-07-22 23:02:28 +00:00
|
|
|
|
2021-08-23 22:53:10 +00:00
|
|
|
pub const fn get_fully_qualified_name() -> &'static str {
|
|
|
|
"TableA"
|
|
|
|
}
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
|
2021-08-23 22:53:10 +00:00
|
|
|
#[inline]
|
2022-09-29 13:58:49 +00:00
|
|
|
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
2021-08-23 22:53:10 +00:00
|
|
|
TableA { _tab: table }
|
|
|
|
}
|
|
|
|
#[allow(unused_mut)]
|
|
|
|
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
|
|
|
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
|
|
|
args: &'args TableAArgs<'args>
|
|
|
|
) -> flatbuffers::WIPOffset<TableA<'bldr>> {
|
|
|
|
let mut builder = TableABuilder::new(_fbb);
|
|
|
|
if let Some(x) = args.b { builder.add_b(x); }
|
|
|
|
builder.finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unpack(&self) -> TableAT {
|
|
|
|
let b = self.b().map(|x| {
|
|
|
|
Box::new(x.unpack())
|
|
|
|
});
|
|
|
|
TableAT {
|
|
|
|
b,
|
2021-07-22 23:02:28 +00:00
|
|
|
}
|
2021-08-23 22:53:10 +00:00
|
|
|
}
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
|
2022-09-29 13:58:49 +00:00
|
|
|
// Safety:
|
|
|
|
// Created from valid Table for this object
|
|
|
|
// which contains a valid value in this slot
|
|
|
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-07 23:37:51 +00:00
|
|
|
impl flatbuffers::Verifiable for TableA<'_> {
|
|
|
|
#[inline]
|
2021-01-04 22:11:59 +00:00
|
|
|
fn run_verifier(
|
|
|
|
v: &mut flatbuffers::Verifier, pos: usize
|
2020-12-07 23:37:51 +00:00
|
|
|
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
|
|
|
use self::flatbuffers::Verifiable;
|
|
|
|
v.visit_table(pos)?
|
2021-07-22 23:02:28 +00:00
|
|
|
.visit_field::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>("b", Self::VT_B, false)?
|
2020-12-07 23:37:51 +00:00
|
|
|
.finish();
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
pub struct TableAArgs<'a> {
|
2020-07-25 20:46:20 +00:00
|
|
|
pub b: Option<flatbuffers::WIPOffset<my_game::other_name_space::TableB<'a>>>,
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
}
|
|
|
|
impl<'a> Default for TableAArgs<'a> {
|
2021-08-23 22:53:10 +00:00
|
|
|
#[inline]
|
|
|
|
fn default() -> Self {
|
|
|
|
TableAArgs {
|
|
|
|
b: None,
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
}
|
2021-08-23 22:53:10 +00:00
|
|
|
}
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
}
|
2022-01-31 00:29:18 +00:00
|
|
|
|
[rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords
Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.
For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.
When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:
```
#[inline]
#[allow(non_snake_case)]
pub fn type__as_int(&self) -> Option<Int<'a>> {
if self.type__type() == Type::Int {
self.type_().map(|u| Int::init_from_table(u))
} else {
None
}
}
```
Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.
* [Rust] Add crate-relative use statements for FBS includes.
At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.
This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?
* Revert "[Rust] Add crate-relative use statements for FBS includes."
This reverts commit d554d79fecf5afd6da6fb993b30b4cd523a5889a.
* Add updated generated test files.
* Fixing Rust test harness to handle new includes.
Test binaries need to add references to generated code that's
transitively included.
This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.
* Test harnesses expect test data to be checked in.
Put include_test2 files into the same directory as the include_test2
schema definition.
Update all code generation scripts (forgot the batch file from last
time).
Path updates in Rust test.
* Include updated generated code
* Address comments raised in PR
* Fix failing Rust tests.
* Previous merge clobbered this branch change.
* Add updated imports to benchmarks.
* Clarifying comment per PR request
* Update documentation comments per feedback
* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel
* Broken code generation batch file
* Fix typo
* Add TODO for tidying up use declaration traversal sometime in the future
* Update test files.
2020-01-19 22:47:28 +00:00
|
|
|
pub struct TableABuilder<'a: 'b, 'b> {
|
|
|
|
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
|
|
|
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
|
|
|
}
|
|
|
|
impl<'a: 'b, 'b> TableABuilder<'a, 'b> {
|
|
|
|
#[inline]
|
|
|
|
pub fn add_b(&mut self, b: flatbuffers::WIPOffset<my_game::other_name_space::TableB<'b >>) {
|
|
|
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<my_game::other_name_space::TableB>>(TableA::VT_B, b);
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> TableABuilder<'a, 'b> {
|
|
|
|
let start = _fbb.start_table();
|
|
|
|
TableABuilder {
|
|
|
|
fbb_: _fbb,
|
|
|
|
start_: start,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
pub fn finish(self) -> flatbuffers::WIPOffset<TableA<'a>> {
|
|
|
|
let o = self.fbb_.end_table(self.start_);
|
|
|
|
flatbuffers::WIPOffset::new(o.value())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 01:40:03 +00:00
|
|
|
impl core::fmt::Debug for TableA<'_> {
|
|
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
2020-10-29 19:57:29 +00:00
|
|
|
let mut ds = f.debug_struct("TableA");
|
|
|
|
ds.field("b", &self.b());
|
|
|
|
ds.finish()
|
|
|
|
}
|
|
|
|
}
|
2021-07-22 23:02:28 +00:00
|
|
|
#[non_exhaustive]
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
pub struct TableAT {
|
|
|
|
pub b: Option<Box<my_game::other_name_space::TableBT>>,
|
|
|
|
}
|
|
|
|
impl Default for TableAT {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
b: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl TableAT {
|
|
|
|
pub fn pack<'b>(
|
|
|
|
&self,
|
|
|
|
_fbb: &mut flatbuffers::FlatBufferBuilder<'b>
|
|
|
|
) -> flatbuffers::WIPOffset<TableA<'b>> {
|
|
|
|
let b = self.b.as_ref().map(|x|{
|
|
|
|
x.pack(_fbb)
|
|
|
|
});
|
|
|
|
TableA::create(_fbb, &TableAArgs{
|
|
|
|
b,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|