Skip to content

Commit

Permalink
Removes size and alignment as rust reserved words
Browse files Browse the repository at this point in the history
  • Loading branch information
csmulhern committed Nov 11, 2024
1 parent 40bf61e commit 9a76029
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion samples/rust_generated/my_game/sample/vec_3_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'b> flatbuffers::Push for Vec3 {
type Output = Vec3;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
4 changes: 1 addition & 3 deletions src/idl_gen_rust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ static std::set<std::string> RustKeywords() {
// Terms that we use ourselves
"follow",
"push",
"size",
"alignment",
"to_little_endian",
"from_little_endian",
"ENUM_MAX",
Expand Down Expand Up @@ -2700,7 +2698,7 @@ class RustGenerator : public BaseGenerator {
code_ += " unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {";
code_ +=
" let src = ::core::slice::from_raw_parts(self as *const "
"{{STRUCT_TY}} as *const u8, Self::size());";
"{{STRUCT_TY}} as *const u8, <Self as flatbuffers::Push>::size());";
code_ += " dst.copy_from_slice(src);";
code_ += " }";
code_ += " #[inline]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'b> flatbuffers::Push for ArrayStruct {
type Output = ArrayStruct;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'b> flatbuffers::Push for NestedStruct {
type Output = NestedStruct;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'b> flatbuffers::Push for Unused {
type Output = Unused;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'b> flatbuffers::Push for Unused {
type Output = Unused;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion tests/monster_test/my_game/example/ability_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'b> flatbuffers::Push for Ability {
type Output = Ability;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Ability as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'b> flatbuffers::Push for StructOfStructs {
type Output = StructOfStructs;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'b> flatbuffers::Push for StructOfStructsOfStructs {
type Output = StructOfStructsOfStructs;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion tests/monster_test/my_game/example/test_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'b> flatbuffers::Push for Test {
type Output = Test;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion tests/monster_test/my_game/example/vec_3_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'b> flatbuffers::Push for Vec3 {
type Output = Vec3;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'b> flatbuffers::Push for Unused {
type Output = Unused;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'b> flatbuffers::Push for Ability {
type Output = Ability;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Ability as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'b> flatbuffers::Push for StructOfStructs {
type Output = StructOfStructs;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'b> flatbuffers::Push for StructOfStructsOfStructs {
type Output = StructOfStructsOfStructs;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'b> flatbuffers::Push for Test {
type Output = Test;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Test as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<'b> flatbuffers::Push for Vec3 {
type Output = Vec3;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'b> flatbuffers::Push for Unused {
type Output = Unused;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'b> flatbuffers::Push for StructInNestedNS {
type Output = StructInNestedNS;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion tests/private_annotation_test/object_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'b> flatbuffers::Push for Object {
type Output = Object;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Object as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Object as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
Expand Down
1 change: 1 addition & 0 deletions tests/rust_namer_test.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct PossiblyReservedWords
// Keywords reserved by Rust namer
follow: float;
push: float;
// Keywords no longer reserved by Rust namer
size: float;
alignment: float;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ impl core::fmt::Debug for PossiblyReservedWords {
f.debug_struct("PossiblyReservedWords")
.field("follow_", &self.follow_())
.field("push_", &self.push_())
.field("size_", &self.size_())
.field("alignment_", &self.alignment_())
.field("size", &self.size())
.field("alignment", &self.alignment())
.finish()
}
}
Expand All @@ -48,9 +48,13 @@ impl<'b> flatbuffers::Push for PossiblyReservedWords {
type Output = PossiblyReservedWords;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const PossiblyReservedWords as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const PossiblyReservedWords as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for PossiblyReservedWords {
Expand All @@ -68,14 +72,14 @@ impl<'a> PossiblyReservedWords {
pub fn new(
follow_: f32,
push_: f32,
size_: f32,
alignment_: f32,
size: f32,
alignment: f32,
) -> Self {
let mut s = Self([0; 16]);
s.set_follow_(follow_);
s.set_push_(push_);
s.set_size_(size_);
s.set_alignment_(alignment_);
s.set_size(size);
s.set_alignment(alignment);
s
}

Expand Down Expand Up @@ -141,7 +145,7 @@ impl<'a> PossiblyReservedWords {
}
}

pub fn size_(&self) -> f32 {
pub fn size(&self) -> f32 {
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
// Safety:
// Created from a valid Table for this object
Expand All @@ -156,7 +160,7 @@ impl<'a> PossiblyReservedWords {
})
}

pub fn set_size_(&mut self, x: f32) {
pub fn set_size(&mut self, x: f32) {
let x_le = x.to_little_endian();
// Safety:
// Created from a valid Table for this object
Expand All @@ -170,7 +174,7 @@ impl<'a> PossiblyReservedWords {
}
}

pub fn alignment_(&self) -> f32 {
pub fn alignment(&self) -> f32 {
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
// Safety:
// Created from a valid Table for this object
Expand All @@ -185,7 +189,7 @@ impl<'a> PossiblyReservedWords {
})
}

pub fn set_alignment_(&mut self, x: f32) {
pub fn set_alignment(&mut self, x: f32) {
let x_le = x.to_little_endian();
// Safety:
// Created from a valid Table for this object
Expand All @@ -203,8 +207,8 @@ impl<'a> PossiblyReservedWords {
PossiblyReservedWordsT {
follow_: self.follow_(),
push_: self.push_(),
size_: self.size_(),
alignment_: self.alignment_(),
size: self.size(),
alignment: self.alignment(),
}
}
}
Expand All @@ -213,16 +217,16 @@ impl<'a> PossiblyReservedWords {
pub struct PossiblyReservedWordsT {
pub follow_: f32,
pub push_: f32,
pub size_: f32,
pub alignment_: f32,
pub size: f32,
pub alignment: f32,
}
impl PossiblyReservedWordsT {
pub fn pack(&self) -> PossiblyReservedWords {
PossiblyReservedWords::new(
self.follow_,
self.push_,
self.size_,
self.alignment_,
self.size,
self.alignment,
)
}
}
Expand Down

0 comments on commit 9a76029

Please sign in to comment.