diff options
author | naure <naure@users.noreply.github.com> | 2019-02-27 08:48:54 +0100 |
---|---|---|
committer | Robert <rw@users.noreply.github.com> | 2019-02-26 23:48:54 -0800 |
commit | 034275c6e23831b3a60adb0d89b842834e3f2e16 (patch) | |
tree | d1add74de52f286d49a18963686e473351ac5b58 /src/idl_gen_rust.cpp | |
parent | 4e5152d886de963162ae81282240bc5377fa10ce (diff) | |
download | flatbuffers-034275c6e23831b3a60adb0d89b842834e3f2e16.tar.gz flatbuffers-034275c6e23831b3a60adb0d89b842834e3f2e16.tar.bz2 flatbuffers-034275c6e23831b3a60adb0d89b842834e3f2e16.zip |
Rust: Fix lifetime in union _as_ accessors (#5140)
* Fix lifetime in union _as_ accessors
In the accessors for union field, the return value is implicitly taking the lifetime of &self.
This is irrelevant and prevents usages of the returned value, because it is needlessly bound to the parent field lifetime.
This patch makes the return value inherit the lifetime of the data, like other methods do.
Diffstat (limited to 'src/idl_gen_rust.cpp')
-rw-r--r-- | src/idl_gen_rust.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index 861a2e9c..fd6a0669 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -1331,8 +1331,8 @@ class RustGenerator : public BaseGenerator { code_ += " #[inline]"; code_ += " #[allow(non_snake_case)]"; - code_ += " pub fn {{FIELD_NAME}}_as_{{U_ELEMENT_NAME}}(&'a self) -> " - "Option<{{U_ELEMENT_TABLE_TYPE}}> {"; + code_ += " pub fn {{FIELD_NAME}}_as_{{U_ELEMENT_NAME}}(&self) -> " + "Option<{{U_ELEMENT_TABLE_TYPE}}<'a>> {"; code_ += " if self.{{FIELD_NAME}}_type() == {{U_ELEMENT_ENUM_TYPE}} {"; code_ += " self.{{FIELD_NAME}}().map(|u| " "{{U_ELEMENT_TABLE_TYPE}}::init_from_table(u))"; |