Skip to content

Commit

Permalink
regenerate and add a test for struct alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
bkietz committed Oct 7, 2024
1 parent d3b781b commit 3316e4a
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 2 deletions.
4 changes: 4 additions & 0 deletions samples/rust_generated/my_game/sample/vec_3_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl<'b> flatbuffers::Push for Vec3 {
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for Vec3 {
Expand Down
4 changes: 2 additions & 2 deletions src/idl_gen_rust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2704,8 +2704,8 @@ class RustGenerator : public BaseGenerator {
code_ += " dst.copy_from_slice(src);";
code_ += " }";
code_ += " #[inline]";
code_ += " fn alignment() -> PushAlignment {";
code_ += " PushAlignment::new({{ALIGN}})";
code_ += " fn alignment() -> flatbuffers::PushAlignment {";
code_ += " flatbuffers::PushAlignment::new({{ALIGN}})";
code_ += " }";
code_ += "}";
code_ += "";
Expand Down
4 changes: 4 additions & 0 deletions tests/arrays_test/my_game/example/array_struct_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ impl<'b> flatbuffers::Push for ArrayStruct {
let src = ::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(8)
}
}

impl<'a> flatbuffers::Verifiable for ArrayStruct {
Expand Down
4 changes: 4 additions & 0 deletions tests/arrays_test/my_game/example/nested_struct_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl<'b> flatbuffers::Push for NestedStruct {
let src = ::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(8)
}
}

impl<'a> flatbuffers::Verifiable for NestedStruct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ impl<'b> flatbuffers::Push for Unused {
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for Unused {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ impl<'b> flatbuffers::Push for Unused {
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for Unused {
Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test/my_game/example/ability_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl<'b> flatbuffers::Push for Ability {
let src = ::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for Ability {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl<'b> flatbuffers::Push for StructOfStructs {
let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for StructOfStructs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ impl<'b> flatbuffers::Push for StructOfStructsOfStructs {
let src = ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for StructOfStructsOfStructs {
Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test/my_game/example/test_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl<'b> flatbuffers::Push for Test {
let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(2)
}
}

impl<'a> flatbuffers::Verifiable for Test {
Expand Down
4 changes: 4 additions & 0 deletions tests/monster_test/my_game/example/vec_3_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ impl<'b> flatbuffers::Push for Vec3 {
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(8)
}
}

impl<'a> flatbuffers::Verifiable for Vec3 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ impl<'b> flatbuffers::Push for Unused {
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for Unused {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl<'b> flatbuffers::Push for Ability {
let src = ::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for Ability {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ impl<'b> flatbuffers::Push for StructOfStructs {
let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for StructOfStructs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl<'b> flatbuffers::Push for StructOfStructsOfStructs {
let src = ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for StructOfStructsOfStructs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl<'b> flatbuffers::Push for Test {
let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(2)
}
}

impl<'a> flatbuffers::Verifiable for Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ impl<'b> flatbuffers::Push for Vec3 {
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(8)
}
}

impl<'a> flatbuffers::Verifiable for Vec3 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ impl<'b> flatbuffers::Push for Unused {
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for Unused {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl<'b> flatbuffers::Push for StructInNestedNS {
let src = ::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for StructInNestedNS {
Expand Down
4 changes: 4 additions & 0 deletions tests/private_annotation_test/object_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ impl<'b> flatbuffers::Push for Object {
let src = ::core::slice::from_raw_parts(self as *const Object as *const u8, Self::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for Object {
Expand Down
8 changes: 8 additions & 0 deletions tests/rust_usage_test/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,14 @@ mod push_impls {
0, 0, 0, 0,
0, 0, 0, 1]);
}

#[test]
fn push_u8_generated_struct_alignment() {
let mut b = flatbuffers::FlatBufferBuilder::new();
b.push(1u8);
b.push(my_game::example::Test::new(10, 20));
check(&b, &[10, 0, 20, 0, 0, 1]);
}
}

#[cfg(test)]
Expand Down

0 comments on commit 3316e4a

Please sign in to comment.