mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-13 16:15:26 +00:00
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:
@@ -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))";
|
||||
|
||||
Reference in New Issue
Block a user