mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-04 12:43:24 +00:00
Remove lifetime specifier on table getter methods (#4949)
With the old-style code, the test fails with a borrow-checker error:
```
#[inline]
pub fn name(&'a self) -> &'a str {
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()
}
```
```
error[E0597]: `e` does not live long enough
--> tests/integration_test.rs:273:57
|
273 | let enemy_of_my_enemy = monster.enemy().map(|e| e.name());
| ^ - `e` dropped here while still borrowed
| |
| borrowed value does not live long enough
274 | assert_eq!(enemy_of_my_enemy, Some("Fred"));
275 | }
| - borrowed value needs to live until here
```
This commit is contained in:
@@ -1263,7 +1263,7 @@ class RustGenerator : public BaseGenerator {
|
||||
|
||||
GenComment(field.doc_comment, " ");
|
||||
code_ += " #[inline]";
|
||||
code_ += " pub fn {{FIELD_NAME}}(&'a self) -> {{RETURN_TYPE}} {";
|
||||
code_ += " pub fn {{FIELD_NAME}}(&self) -> {{RETURN_TYPE}} {";
|
||||
code_ += " {{FUNC_BODY}}";
|
||||
code_ += " }";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user