forked from BigfootDev/flatbuffers
Removes 'size' and 'alignment' as Rust keywords (#8139)
* Adds fields for possibly reserved words to rust_namer_test * Removes size and alignment as rust reserved words
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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",
|
||||
@@ -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]";
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -16,12 +16,22 @@ table PlayerInputChange {}
|
||||
|
||||
union GameMessage
|
||||
{
|
||||
PlayerStatEvent,
|
||||
PlayerSpectate,
|
||||
PlayerStatEvent,
|
||||
PlayerSpectate,
|
||||
PlayerInputChange
|
||||
}
|
||||
|
||||
table GameMessageWrapper
|
||||
{
|
||||
Message:GameMessage;
|
||||
}
|
||||
}
|
||||
|
||||
struct PossiblyReservedWords
|
||||
{
|
||||
// Keywords reserved by Rust namer
|
||||
follow: float;
|
||||
push: float;
|
||||
// Keywords no longer reserved by Rust namer
|
||||
size: float;
|
||||
alignment: float;
|
||||
}
|
||||
|
||||
@@ -18,4 +18,6 @@ pub mod rust_namer_test {
|
||||
pub use self::player_input_change_generated::*;
|
||||
mod game_message_wrapper_generated;
|
||||
pub use self::game_message_wrapper_generated::*;
|
||||
mod possibly_reserved_words_generated;
|
||||
pub use self::possibly_reserved_words_generated::*;
|
||||
} // rust_namer_test
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
// struct PossiblyReservedWords, aligned to 4
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub struct PossiblyReservedWords(pub [u8; 16]);
|
||||
impl Default for PossiblyReservedWords {
|
||||
fn default() -> Self {
|
||||
Self([0; 16])
|
||||
}
|
||||
}
|
||||
impl core::fmt::Debug for PossiblyReservedWords {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
f.debug_struct("PossiblyReservedWords")
|
||||
.field("follow_", &self.follow_())
|
||||
.field("push_", &self.push_())
|
||||
.field("size", &self.size())
|
||||
.field("alignment", &self.alignment())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for PossiblyReservedWords {}
|
||||
impl<'a> flatbuffers::Follow<'a> for PossiblyReservedWords {
|
||||
type Inner = &'a PossiblyReservedWords;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a PossiblyReservedWords>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a PossiblyReservedWords {
|
||||
type Inner = &'a PossiblyReservedWords;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<PossiblyReservedWords>(buf, loc)
|
||||
}
|
||||
}
|
||||
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 as flatbuffers::Push>::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
#[inline]
|
||||
fn alignment() -> flatbuffers::PushAlignment {
|
||||
flatbuffers::PushAlignment::new(4)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for PossiblyReservedWords {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.in_buffer::<Self>(pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PossiblyReservedWords {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
follow_: f32,
|
||||
push_: 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
|
||||
}
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"RustNamerTest.PossiblyReservedWords"
|
||||
}
|
||||
|
||||
pub fn follow_(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_follow_(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[4..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_push_(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[4..].as_mut_ptr(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[8..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_size(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[8..].as_mut_ptr(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[12..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_alignment(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[12..].as_mut_ptr(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> PossiblyReservedWordsT {
|
||||
PossiblyReservedWordsT {
|
||||
follow_: self.follow_(),
|
||||
push_: self.push_(),
|
||||
size: self.size(),
|
||||
alignment: self.alignment(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct PossiblyReservedWordsT {
|
||||
pub follow_: f32,
|
||||
pub push_: f32,
|
||||
pub size: f32,
|
||||
pub alignment: f32,
|
||||
}
|
||||
impl PossiblyReservedWordsT {
|
||||
pub fn pack(&self) -> PossiblyReservedWords {
|
||||
PossiblyReservedWords::new(
|
||||
self.follow_,
|
||||
self.push_,
|
||||
self.size,
|
||||
self.alignment,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user