diff options
author | Casper <casperneo@uchicago.edu> | 2020-11-05 13:58:06 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-05 13:58:06 -0800 |
commit | 46a8c7e958c52d16e141338b6a48f74a1136acff (patch) | |
tree | f78bcef6685400c04314a6e1de8a8c3649a3ae55 /src/idl_gen_rust.cpp | |
parent | bc56c553ec400e5b270de4b0bf26b3591cb050a5 (diff) | |
download | flatbuffers-46a8c7e958c52d16e141338b6a48f74a1136acff.tar.gz flatbuffers-46a8c7e958c52d16e141338b6a48f74a1136acff.tar.bz2 flatbuffers-46a8c7e958c52d16e141338b6a48f74a1136acff.zip |
Added required-nested-flatbuffer to monster_test and fixed rust (#6236)
Co-authored-by: Casper Neo <cneo@google.com>
Diffstat (limited to 'src/idl_gen_rust.cpp')
-rw-r--r-- | src/idl_gen_rust.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index b6434c84..3995a7f2 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -1302,13 +1302,21 @@ class RustGenerator : public BaseGenerator { code_.SetValue("NESTED", WrapInNameSpace(*nested_root)); code_ += - " pub fn {{FIELD_NAME}}_nested_flatbuffer(&'a self) -> " - "Option<{{NESTED}}<'a>> {"; - code_ += " self.{{FIELD_NAME}}().map(|data| {"; - code_ += " use flatbuffers::Follow;"; - code_ += " <flatbuffers::ForwardsUOffset<{{NESTED}}<'a>>>" - "::follow(data, 0)"; - code_ += " })"; + " pub fn {{FIELD_NAME}}_nested_flatbuffer(&'a self) -> \\"; + if (field.required) { + code_ += "{{NESTED}}<'a> {"; + code_ += " let data = self.{{FIELD_NAME}}();"; + code_ += " use flatbuffers::Follow;"; + code_ += " <flatbuffers::ForwardsUOffset<{{NESTED}}<'a>>>" + "::follow(data, 0)"; + } else { + code_ += "Option<{{NESTED}}<'a>> {"; + code_ += " self.{{FIELD_NAME}}().map(|data| {"; + code_ += " use flatbuffers::Follow;"; + code_ += " <flatbuffers::ForwardsUOffset<{{NESTED}}<'a>>>" + "::follow(data, 0)"; + code_ += " })"; + } code_ += " }"; } }); |