Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: Add Follow with a different lifetime #7540

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rust/flatbuffers/src/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ impl<'a, T: Follow<'a>> Follow<'a> for FollowStart<T> {
T::follow(buf, loc)
}
}

pub trait FollowWith<'a> {
type Inner: Follow<'a>;
}
2 changes: 1 addition & 1 deletion rust/flatbuffers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub use crate::builder::FlatBufferBuilder;
pub use crate::endian_scalar::{
byte_swap_f32, byte_swap_f64, emplace_scalar, read_scalar, read_scalar_at, EndianScalar,
};
pub use crate::follow::{Follow, FollowStart};
pub use crate::follow::{Follow, FollowStart, FollowWith};
pub use crate::primitives::*;
pub use crate::push::Push;
pub use crate::table::{buffer_has_identifier, Table};
Expand Down
4 changes: 4 additions & 0 deletions samples/rust_generated/my_game/sample/monster_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Monster<'b> {
type Inner = Monster<'a>;
}

impl<'a> Monster<'a> {
pub const VT_POS: flatbuffers::VOffsetT = 4;
pub const VT_MANA: flatbuffers::VOffsetT = 6;
Expand Down
4 changes: 4 additions & 0 deletions samples/rust_generated/my_game/sample/weapon_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for Weapon<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Weapon<'b> {
type Inner = Weapon<'a>;
}

impl<'a> Weapon<'a> {
pub const VT_NAME: flatbuffers::VOffsetT = 4;
pub const VT_DAMAGE: flatbuffers::VOffsetT = 6;
Expand Down
4 changes: 4 additions & 0 deletions src/idl_gen_rust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,10 @@ class RustGenerator : public BaseGenerator {
code_ += " }";
code_ += "}";
code_ += "";
code_ += "impl<'a, 'b> flatbuffers::FollowWith<'a> for {{STRUCT_TY}}<'b> {";
code_ += " type Inner = {{STRUCT_TY}}<'a>;";
code_ += "}";
code_ += "";
code_ += "impl<'a> {{STRUCT_TY}}<'a> {";

// Generate field id constants.
Expand Down
4 changes: 4 additions & 0 deletions tests/arrays_test/my_game/example/array_table_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for ArrayTable<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for ArrayTable<'b> {
type Inner = ArrayTable<'a>;
}

impl<'a> ArrayTable<'a> {
pub const VT_A: flatbuffers::VOffsetT = 4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableB<'b> {
type Inner = TableB<'a>;
}

impl<'a> TableB<'a> {
pub const VT_A: flatbuffers::VOffsetT = 4;

Expand Down
4 changes: 4 additions & 0 deletions tests/include_test1/table_a_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableA<'b> {
type Inner = TableA<'a>;
}

impl<'a> TableA<'a> {
pub const VT_B: flatbuffers::VOffsetT = 4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableB<'b> {
type Inner = TableB<'a>;
}

impl<'a> TableB<'a> {
pub const VT_A: flatbuffers::VOffsetT = 4;

Expand Down
4 changes: 4 additions & 0 deletions tests/include_test2/table_a_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableA<'b> {
type Inner = TableA<'a>;
}

impl<'a> TableA<'a> {
pub const VT_B: flatbuffers::VOffsetT = 4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for KeywordsInTable<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for KeywordsInTable<'b> {
type Inner = KeywordsInTable<'a>;
}

impl<'a> KeywordsInTable<'a> {
pub const VT_IS: flatbuffers::VOffsetT = 4;
pub const VT_PRIVATE: flatbuffers::VOffsetT = 6;
Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test/my_game/example/monster_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Monster<'b> {
type Inner = Monster<'a>;
}

impl<'a> Monster<'a> {
pub const VT_POS: flatbuffers::VOffsetT = 4;
pub const VT_MANA: flatbuffers::VOffsetT = 6;
Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test/my_game/example/referrable_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for Referrable<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Referrable<'b> {
type Inner = Referrable<'a>;
}

impl<'a> Referrable<'a> {
pub const VT_ID: flatbuffers::VOffsetT = 4;

Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test/my_game/example/stat_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for Stat<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Stat<'b> {
type Inner = Stat<'a>;
}

impl<'a> Stat<'a> {
pub const VT_ID: flatbuffers::VOffsetT = 4;
pub const VT_VAL: flatbuffers::VOffsetT = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TestSimpleTableWithEnum<'b> {
type Inner = TestSimpleTableWithEnum<'a>;
}

impl<'a> TestSimpleTableWithEnum<'a> {
pub const VT_COLOR: flatbuffers::VOffsetT = 4;

Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test/my_game/example/type_aliases_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TypeAliases<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TypeAliases<'b> {
type Inner = TypeAliases<'a>;
}

impl<'a> TypeAliases<'a> {
pub const VT_I8_: flatbuffers::VOffsetT = 4;
pub const VT_U8_: flatbuffers::VOffsetT = 6;
Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test/my_game/example_2/monster_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Monster<'b> {
type Inner = Monster<'a>;
}

impl<'a> Monster<'a> {

pub const fn get_fully_qualified_name() -> &'static str {
Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test/my_game/in_parent_namespace_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for InParentNamespace<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for InParentNamespace<'b> {
type Inner = InParentNamespace<'a>;
}

impl<'a> InParentNamespace<'a> {

pub const fn get_fully_qualified_name() -> &'static str {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableB<'b> {
type Inner = TableB<'a>;
}

impl<'a> TableB<'a> {
pub const VT_A: flatbuffers::VOffsetT = 4;

Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test/table_a_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableA<'b> {
type Inner = TableA<'a>;
}

impl<'a> TableA<'a> {
pub const VT_B: flatbuffers::VOffsetT = 4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Monster<'b> {
type Inner = Monster<'a>;
}

impl<'a> Monster<'a> {
pub const VT_POS: flatbuffers::VOffsetT = 4;
pub const VT_MANA: flatbuffers::VOffsetT = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ impl<'a> flatbuffers::Follow<'a> for Referrable<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Referrable<'b> {
type Inner = Referrable<'a>;
}

impl<'a> Referrable<'a> {
pub const VT_ID: flatbuffers::VOffsetT = 4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ impl<'a> flatbuffers::Follow<'a> for Stat<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Stat<'b> {
type Inner = Stat<'a>;
}

impl<'a> Stat<'a> {
pub const VT_ID: flatbuffers::VOffsetT = 4;
pub const VT_VAL: flatbuffers::VOffsetT = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ impl<'a> flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TestSimpleTableWithEnum<'b> {
type Inner = TestSimpleTableWithEnum<'a>;
}

impl<'a> TestSimpleTableWithEnum<'a> {
pub const VT_COLOR: flatbuffers::VOffsetT = 4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ impl<'a> flatbuffers::Follow<'a> for TypeAliases<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TypeAliases<'b> {
type Inner = TypeAliases<'a>;
}

impl<'a> TypeAliases<'a> {
pub const VT_I8_: flatbuffers::VOffsetT = 4;
pub const VT_U8_: flatbuffers::VOffsetT = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Monster<'b> {
type Inner = Monster<'a>;
}

impl<'a> Monster<'a> {

pub const fn get_fully_qualified_name() -> &'static str {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ impl<'a> flatbuffers::Follow<'a> for InParentNamespace<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for InParentNamespace<'b> {
type Inner = InParentNamespace<'a>;
}

impl<'a> InParentNamespace<'a> {

pub const fn get_fully_qualified_name() -> &'static str {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableB<'b> {
type Inner = TableB<'a>;
}

impl<'a> TableB<'a> {
pub const VT_A: flatbuffers::VOffsetT = 4;

Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test_serialize/table_a_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableA<'b> {
type Inner = TableA<'a>;
}

impl<'a> TableA<'a> {
pub const VT_B: flatbuffers::VOffsetT = 4;

Expand Down
4 changes: 4 additions & 0 deletions tests/more_defaults/more_defaults_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for MoreDefaults<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for MoreDefaults<'b> {
type Inner = MoreDefaults<'a>;
}

impl<'a> MoreDefaults<'a> {
pub const VT_INTS: flatbuffers::VOffsetT = 4;
pub const VT_FLOATS: flatbuffers::VOffsetT = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TableInNestedNS<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableInNestedNS<'b> {
type Inner = TableInNestedNS<'a>;
}

impl<'a> TableInNestedNS<'a> {
pub const VT_FOO: flatbuffers::VOffsetT = 4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for SecondTableInA<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for SecondTableInA<'b> {
type Inner = SecondTableInA<'a>;
}

impl<'a> SecondTableInA<'a> {
pub const VT_REFER_TO_C: flatbuffers::VOffsetT = 4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TableInFirstNS<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableInFirstNS<'b> {
type Inner = TableInFirstNS<'a>;
}

impl<'a> TableInFirstNS<'a> {
pub const VT_FOO_TABLE: flatbuffers::VOffsetT = 4;
pub const VT_FOO_ENUM: flatbuffers::VOffsetT = 6;
Expand Down
4 changes: 4 additions & 0 deletions tests/namespace_test/namespace_c/table_in_c_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for TableInC<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for TableInC<'b> {
type Inner = TableInC<'a>;
}

impl<'a> TableInC<'a> {
pub const VT_REFER_TO_A1: flatbuffers::VOffsetT = 4;
pub const VT_REFER_TO_A2: flatbuffers::VOffsetT = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for ScalarStuff<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for ScalarStuff<'b> {
type Inner = ScalarStuff<'a>;
}

impl<'a> ScalarStuff<'a> {
pub const VT_JUST_I8: flatbuffers::VOffsetT = 4;
pub const VT_MAYBE_I8: flatbuffers::VOffsetT = 6;
Expand Down
4 changes: 4 additions & 0 deletions tests/private_annotation_test/annotations_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> flatbuffers::Follow<'a> for Annotations<'a> {
}
}

impl<'a, 'b> flatbuffers::FollowWith<'a> for Annotations<'b> {
type Inner = Annotations<'a>;
}

impl<'a> Annotations<'a> {
pub const VT_VALUE: flatbuffers::VOffsetT = 4;

Expand Down
Loading