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.
This commit is contained in:
naure
2019-02-27 08:48:54 +01:00
committed by Robert
parent 4e5152d886
commit 034275c6e2
2 changed files with 11 additions and 11 deletions

View File

@@ -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))";