Rust soundness fixes (#7518)

* Rust soundness fixes

* Second pass

* Make init_from_table unsafe

* Remove SafeSliceAccess

* Clippy

* Remove create_vector_of_strings

* More clippy

* Remove deprecated root type accessors

* More soundness fixes

* Fix EndianScalar for bool

* Add TriviallyTransmutable

* Add debug assertions

* Review comments

* Review feedback
This commit is contained in:
Raphael Taylor-Davies
2022-09-29 14:58:49 +01:00
committed by GitHub
parent dadbff5714
commit 374f8fb5fb
102 changed files with 2673 additions and 2035 deletions

View File

@@ -32,39 +32,25 @@ impl core::fmt::Debug for ArrayStruct {
}
impl flatbuffers::SimpleToVerifyInSlice for ArrayStruct {}
impl flatbuffers::SafeSliceAccess for ArrayStruct {}
impl<'a> flatbuffers::Follow<'a> for ArrayStruct {
type Inner = &'a ArrayStruct;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a ArrayStruct>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a ArrayStruct {
type Inner = &'a ArrayStruct;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<ArrayStruct>(buf, loc)
}
}
impl<'b> flatbuffers::Push for ArrayStruct {
type Output = ArrayStruct;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b ArrayStruct {
type Output = ArrayStruct;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const ArrayStruct as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -104,64 +90,88 @@ impl<'a> ArrayStruct {
}
pub fn a(&self) -> f32 {
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
unsafe {
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>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_a(&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 f32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<f32>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
}
}
pub fn b(&'a self) -> flatbuffers::Array<'a, i32, 15> {
flatbuffers::Array::follow(&self.0, 4)
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe { flatbuffers::Array::follow(&self.0, 4) }
}
pub fn set_b(&mut self, items: &[i32; 15]) {
flatbuffers::emplace_scalar_array(&mut self.0, 4, items);
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 4, items) };
}
pub fn c(&self) -> i8 {
let mut mem = core::mem::MaybeUninit::<i8>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i8 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[64..].as_ptr(),
mem.as_mut_ptr() as *mut u8,
core::mem::size_of::<i8>(),
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_c(&mut self, x: i8) {
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 i8 as *const u8,
&x_le as *const _ as *const u8,
self.0[64..].as_mut_ptr(),
core::mem::size_of::<i8>(),
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
);
}
}
pub fn d(&'a self) -> flatbuffers::Array<'a, NestedStruct, 2> {
flatbuffers::Array::follow(&self.0, 72)
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe { flatbuffers::Array::follow(&self.0, 72) }
}
pub fn set_d(&mut self, x: &[NestedStruct; 2]) {
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe {
core::ptr::copy(
x.as_ptr() as *const u8,
@@ -172,34 +182,46 @@ impl<'a> ArrayStruct {
}
pub fn e(&self) -> i32 {
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i32 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[136..].as_ptr(),
mem.as_mut_ptr() as *mut u8,
core::mem::size_of::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_e(&mut self, x: i32) {
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 i32 as *const u8,
&x_le as *const _ as *const u8,
self.0[136..].as_mut_ptr(),
core::mem::size_of::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
}
}
pub fn f(&'a self) -> flatbuffers::Array<'a, i64, 2> {
flatbuffers::Array::follow(&self.0, 144)
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe { flatbuffers::Array::follow(&self.0, 144) }
}
pub fn set_f(&mut self, items: &[i64; 2]) {
flatbuffers::emplace_scalar_array(&mut self.0, 144, items);
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 144, items) };
}
pub fn unpack(&self) -> ArrayStructT {

View File

@@ -19,8 +19,8 @@ pub struct ArrayTable<'a> {
impl<'a> flatbuffers::Follow<'a> for ArrayTable<'a> {
type Inner = ArrayTable<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> ArrayTable<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
ArrayTable { _tab: table }
}
#[allow(unused_mut)]
@@ -56,7 +56,10 @@ impl<'a> ArrayTable<'a> {
#[inline]
pub fn a(&self) -> Option<&'a ArrayStruct> {
self._tab.get::<ArrayStruct>(ArrayTable::VT_A, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<ArrayStruct>(ArrayTable::VT_A, None)}
}
}
@@ -139,18 +142,6 @@ impl ArrayTableT {
})
}
}
#[inline]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_root_as_array_table<'a>(buf: &'a [u8]) -> ArrayTable<'a> {
unsafe { flatbuffers::root_unchecked::<ArrayTable<'a>>(buf) }
}
#[inline]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_size_prefixed_root_as_array_table<'a>(buf: &'a [u8]) -> ArrayTable<'a> {
unsafe { flatbuffers::size_prefixed_root_unchecked::<ArrayTable<'a>>(buf) }
}
#[inline]
/// Verifies that a buffer of bytes contains a `ArrayTable`
/// and returns it.

View File

@@ -30,39 +30,25 @@ impl core::fmt::Debug for NestedStruct {
}
impl flatbuffers::SimpleToVerifyInSlice for NestedStruct {}
impl flatbuffers::SafeSliceAccess for NestedStruct {}
impl<'a> flatbuffers::Follow<'a> for NestedStruct {
type Inner = &'a NestedStruct;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a NestedStruct>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a NestedStruct {
type Inner = &'a NestedStruct;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<NestedStruct>(buf, loc)
}
}
impl<'b> flatbuffers::Push for NestedStruct {
type Output = NestedStruct;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b NestedStruct {
type Output = NestedStruct;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const NestedStruct as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -98,41 +84,59 @@ impl<'a> NestedStruct {
}
pub fn a(&'a self) -> flatbuffers::Array<'a, i32, 2> {
flatbuffers::Array::follow(&self.0, 0)
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe { flatbuffers::Array::follow(&self.0, 0) }
}
pub fn set_a(&mut self, items: &[i32; 2]) {
flatbuffers::emplace_scalar_array(&mut self.0, 0, items);
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 0, items) };
}
pub fn b(&self) -> TestEnum {
let mut mem = core::mem::MaybeUninit::<TestEnum>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<TestEnum 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::<TestEnum>(),
core::mem::size_of::<<TestEnum as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_b(&mut self, x: TestEnum) {
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 TestEnum as *const u8,
&x_le as *const _ as *const u8,
self.0[8..].as_mut_ptr(),
core::mem::size_of::<TestEnum>(),
core::mem::size_of::<<TestEnum as EndianScalar>::Scalar>(),
);
}
}
pub fn c(&'a self) -> flatbuffers::Array<'a, TestEnum, 2> {
flatbuffers::Array::follow(&self.0, 9)
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe { flatbuffers::Array::follow(&self.0, 9) }
}
pub fn set_c(&mut self, x: &[TestEnum; 2]) {
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe {
core::ptr::copy(
x.as_ptr() as *const u8,
@@ -143,11 +147,17 @@ impl<'a> NestedStruct {
}
pub fn d(&'a self) -> flatbuffers::Array<'a, i64, 2> {
flatbuffers::Array::follow(&self.0, 16)
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe { flatbuffers::Array::follow(&self.0, 16) }
}
pub fn set_d(&mut self, items: &[i64; 2]) {
flatbuffers::emplace_scalar_array(&mut self.0, 16, items);
// Safety:
// Created from a valid Table for this object
// Which contains a valid array in this slot
unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 16, items) };
}
pub fn unpack(&self) -> NestedStructT {

View File

@@ -59,10 +59,8 @@ impl core::fmt::Debug for TestEnum {
impl<'a> flatbuffers::Follow<'a> for TestEnum {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
Self(b)
}
}
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for TestEnum {
impl flatbuffers::Push for TestEnum {
type Output = TestEnum;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for TestEnum {
type Scalar = i8;
#[inline]
fn to_little_endian(self) -> Self {
let b = i8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i8::from_le(self.0);
fn from_little_endian(v: i8) -> Self {
let b = i8::from_le(v);
Self(b)
}
}

View File

@@ -51,10 +51,8 @@ impl core::fmt::Debug for FromInclude {
impl<'a> flatbuffers::Follow<'a> for FromInclude {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i64>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
Self(b)
}
}
@@ -62,21 +60,21 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
impl flatbuffers::Push for FromInclude {
type Output = FromInclude;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i64>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i64>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for FromInclude {
type Scalar = i64;
#[inline]
fn to_little_endian(self) -> Self {
let b = i64::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i64 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i64::from_le(self.0);
fn from_little_endian(v: i64) -> Self {
let b = i64::from_le(v);
Self(b)
}
}

View File

@@ -19,8 +19,8 @@ pub struct TableB<'a> {
impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
type Inner = TableB<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> TableB<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableB { _tab: table }
}
#[allow(unused_mut)]
@@ -56,7 +56,10 @@ impl<'a> TableB<'a> {
#[inline]
pub fn a(&self) -> Option<super::super::TableA<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)}
}
}

View File

@@ -27,39 +27,25 @@ impl core::fmt::Debug for Unused {
}
impl flatbuffers::SimpleToVerifyInSlice for Unused {}
impl flatbuffers::SafeSliceAccess for Unused {}
impl<'a> flatbuffers::Follow<'a> for Unused {
type Inner = &'a Unused;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Unused>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Unused {
type Inner = &'a Unused;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Unused>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Unused {
type Output = Unused;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Unused {
type Output = Unused;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -89,24 +75,30 @@ impl<'a> Unused {
}
pub fn a(&self) -> i32 {
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i32 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::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_a(&mut self, x: i32) {
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 i32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
}
}

View File

@@ -19,8 +19,8 @@ pub struct TableA<'a> {
impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
type Inner = TableA<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> TableA<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableA { _tab: table }
}
#[allow(unused_mut)]
@@ -56,7 +56,10 @@ impl<'a> TableA<'a> {
#[inline]
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
}
}

View File

@@ -51,10 +51,8 @@ impl core::fmt::Debug for FromInclude {
impl<'a> flatbuffers::Follow<'a> for FromInclude {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i64>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
Self(b)
}
}
@@ -62,21 +60,21 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
impl flatbuffers::Push for FromInclude {
type Output = FromInclude;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i64>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i64>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for FromInclude {
type Scalar = i64;
#[inline]
fn to_little_endian(self) -> Self {
let b = i64::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i64 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i64::from_le(self.0);
fn from_little_endian(v: i64) -> Self {
let b = i64::from_le(v);
Self(b)
}
}

View File

@@ -19,8 +19,8 @@ pub struct TableB<'a> {
impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
type Inner = TableB<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> TableB<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableB { _tab: table }
}
#[allow(unused_mut)]
@@ -56,7 +56,10 @@ impl<'a> TableB<'a> {
#[inline]
pub fn a(&self) -> Option<super::super::TableA<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)}
}
}

View File

@@ -27,39 +27,25 @@ impl core::fmt::Debug for Unused {
}
impl flatbuffers::SimpleToVerifyInSlice for Unused {}
impl flatbuffers::SafeSliceAccess for Unused {}
impl<'a> flatbuffers::Follow<'a> for Unused {
type Inner = &'a Unused;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Unused>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Unused {
type Inner = &'a Unused;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Unused>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Unused {
type Output = Unused;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Unused {
type Output = Unused;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -89,24 +75,30 @@ impl<'a> Unused {
}
pub fn a(&self) -> i32 {
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i32 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::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_a(&mut self, x: i32) {
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 i32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
}
}

View File

@@ -19,8 +19,8 @@ pub struct TableA<'a> {
impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
type Inner = TableA<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> TableA<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableA { _tab: table }
}
#[allow(unused_mut)]
@@ -56,7 +56,10 @@ impl<'a> TableA<'a> {
#[inline]
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
}
}

View File

@@ -59,10 +59,8 @@ impl core::fmt::Debug for ABC {
impl<'a> flatbuffers::Follow<'a> for ABC {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i32>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i32>(buf, loc);
Self(b)
}
}
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for ABC {
impl flatbuffers::Push for ABC {
type Output = ABC;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i32>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i32>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for ABC {
type Scalar = i32;
#[inline]
fn to_little_endian(self) -> Self {
let b = i32::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i32 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i32::from_le(self.0);
fn from_little_endian(v: i32) -> Self {
let b = i32::from_le(v);
Self(b)
}
}

View File

@@ -19,8 +19,8 @@ pub struct KeywordsInTable<'a> {
impl<'a> flatbuffers::Follow<'a> for KeywordsInTable<'a> {
type Inner = KeywordsInTable<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -35,7 +35,7 @@ impl<'a> KeywordsInTable<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
KeywordsInTable { _tab: table }
}
#[allow(unused_mut)]
@@ -66,19 +66,31 @@ impl<'a> KeywordsInTable<'a> {
#[inline]
pub fn is(&self) -> ABC {
self._tab.get::<ABC>(KeywordsInTable::VT_IS, Some(ABC::void)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<ABC>(KeywordsInTable::VT_IS, Some(ABC::void)).unwrap()}
}
#[inline]
pub fn private(&self) -> public {
self._tab.get::<public>(KeywordsInTable::VT_PRIVATE, Some(public::NONE)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<public>(KeywordsInTable::VT_PRIVATE, Some(public::NONE)).unwrap()}
}
#[inline]
pub fn type_(&self) -> i32 {
self._tab.get::<i32>(KeywordsInTable::VT_TYPE_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(KeywordsInTable::VT_TYPE_, Some(0)).unwrap()}
}
#[inline]
pub fn default(&self) -> bool {
self._tab.get::<bool>(KeywordsInTable::VT_DEFAULT, Some(false)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<bool>(KeywordsInTable::VT_DEFAULT, Some(false)).unwrap()}
}
}

View File

@@ -59,10 +59,8 @@ impl core::fmt::Debug for KeywordsInUnion {
impl<'a> flatbuffers::Follow<'a> for KeywordsInUnion {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
Self(b)
}
}
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for KeywordsInUnion {
impl flatbuffers::Push for KeywordsInUnion {
type Output = KeywordsInUnion;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for KeywordsInUnion {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> u8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.0);
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
Self(b)
}
}

View File

@@ -51,10 +51,8 @@ impl core::fmt::Debug for public {
impl<'a> flatbuffers::Follow<'a> for public {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i32>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i32>(buf, loc);
Self(b)
}
}
@@ -62,21 +60,21 @@ impl<'a> flatbuffers::Follow<'a> for public {
impl flatbuffers::Push for public {
type Output = public;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i32>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i32>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for public {
type Scalar = i32;
#[inline]
fn to_little_endian(self) -> Self {
let b = i32::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i32 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i32::from_le(self.0);
fn from_little_endian(v: i32) -> Self {
let b = i32::from_le(v);
Self(b)
}
}

View File

@@ -28,39 +28,25 @@ impl core::fmt::Debug for Ability {
}
impl flatbuffers::SimpleToVerifyInSlice for Ability {}
impl flatbuffers::SafeSliceAccess for Ability {}
impl<'a> flatbuffers::Follow<'a> for Ability {
type Inner = &'a Ability;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Ability>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Ability {
type Inner = &'a Ability;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Ability>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Ability {
type Output = Ability;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Ability {
type Output = Ability;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Ability as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -92,24 +78,30 @@ impl<'a> Ability {
}
pub fn id(&self) -> u32 {
let mut mem = core::mem::MaybeUninit::<u32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<u32 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::<u32>(),
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_id(&mut self, x: u32) {
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 u32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<u32>(),
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
);
}
}
@@ -125,24 +117,30 @@ impl<'a> Ability {
key.cmp(&val)
}
pub fn distance(&self) -> u32 {
let mut mem = core::mem::MaybeUninit::<u32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<u32 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::<u32>(),
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_distance(&mut self, x: u32) {
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 u32 as *const u8,
&x_le as *const _ as *const u8,
self.0[4..].as_mut_ptr(),
core::mem::size_of::<u32>(),
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
);
}
}

View File

@@ -63,10 +63,8 @@ impl core::fmt::Debug for AnyAmbiguousAliases {
impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
Self(b)
}
}
@@ -74,21 +72,21 @@ impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
impl flatbuffers::Push for AnyAmbiguousAliases {
type Output = AnyAmbiguousAliases;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for AnyAmbiguousAliases {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> u8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.0);
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
Self(b)
}
}

View File

@@ -63,10 +63,8 @@ impl core::fmt::Debug for Any {
impl<'a> flatbuffers::Follow<'a> for Any {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
Self(b)
}
}
@@ -74,21 +72,21 @@ impl<'a> flatbuffers::Follow<'a> for Any {
impl flatbuffers::Push for Any {
type Output = Any;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for Any {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> u8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.0);
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
Self(b)
}
}

View File

@@ -63,10 +63,8 @@ impl core::fmt::Debug for AnyUniqueAliases {
impl<'a> flatbuffers::Follow<'a> for AnyUniqueAliases {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
Self(b)
}
}
@@ -74,21 +72,21 @@ impl<'a> flatbuffers::Follow<'a> for AnyUniqueAliases {
impl flatbuffers::Push for AnyUniqueAliases {
type Output = AnyUniqueAliases;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for AnyUniqueAliases {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> u8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.0);
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
Self(b)
}
}

View File

@@ -29,32 +29,38 @@ pub use self::bitflags_color::Color;
impl<'a> flatbuffers::Follow<'a> for Color {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe { Self::from_bits_unchecked(b) }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
// Safety:
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
// https://github.com/bitflags/bitflags/issues/262
Self::from_bits_unchecked(b)
}
}
impl flatbuffers::Push for Color {
type Output = Color;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.bits()); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.bits());
}
}
impl flatbuffers::EndianScalar for Color {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.bits());
unsafe { Self::from_bits_unchecked(b) }
fn to_little_endian(self) -> u8 {
self.bits().to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.bits());
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
// Safety:
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
// https://github.com/bitflags/bitflags/issues/262
unsafe { Self::from_bits_unchecked(b) }
}
}

View File

@@ -25,32 +25,38 @@ pub use self::bitflags_long_enum::LongEnum;
impl<'a> flatbuffers::Follow<'a> for LongEnum {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u64>(buf, loc)
};
unsafe { Self::from_bits_unchecked(b) }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u64>(buf, loc);
// Safety:
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
// https://github.com/bitflags/bitflags/issues/262
Self::from_bits_unchecked(b)
}
}
impl flatbuffers::Push for LongEnum {
type Output = LongEnum;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u64>(dst, self.bits()); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u64>(dst, self.bits());
}
}
impl flatbuffers::EndianScalar for LongEnum {
type Scalar = u64;
#[inline]
fn to_little_endian(self) -> Self {
let b = u64::to_le(self.bits());
unsafe { Self::from_bits_unchecked(b) }
fn to_little_endian(self) -> u64 {
self.bits().to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u64::from_le(self.bits());
fn from_little_endian(v: u64) -> Self {
let b = u64::from_le(v);
// Safety:
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
// https://github.com/bitflags/bitflags/issues/262
unsafe { Self::from_bits_unchecked(b) }
}
}

View File

@@ -20,8 +20,8 @@ pub struct Monster<'a> {
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
type Inner = Monster<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -85,7 +85,7 @@ impl<'a> Monster<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
Monster { _tab: table }
}
#[allow(unused_mut)]
@@ -161,7 +161,7 @@ impl<'a> Monster<'a> {
x.to_string()
};
let inventory = self.inventory().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let color = self.color();
let test = match self.test_type() {
@@ -196,7 +196,7 @@ impl<'a> Monster<'a> {
Box::new(x.unpack())
});
let testnestedflatbuffer = self.testnestedflatbuffer().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let testempty = self.testempty().map(|x| {
Box::new(x.unpack())
@@ -211,7 +211,7 @@ impl<'a> Monster<'a> {
let testhashs64_fnv1a = self.testhashs64_fnv1a();
let testhashu64_fnv1a = self.testhashu64_fnv1a();
let testarrayofbools = self.testarrayofbools().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let testf = self.testf();
let testf2 = self.testf2();
@@ -223,7 +223,7 @@ impl<'a> Monster<'a> {
x.iter().map(|t| t.unpack()).collect()
});
let flex = self.flex().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let test5 = self.test5().map(|x| {
x.iter().map(|t| t.unpack()).collect()
@@ -298,7 +298,7 @@ impl<'a> Monster<'a> {
});
let signed_enum = self.signed_enum();
let testrequirednestedflatbuffer = self.testrequirednestedflatbuffer().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let scalar_key_sorted_tables = self.scalar_key_sorted_tables().map(|x| {
x.iter().map(|t| t.unpack()).collect()
@@ -364,19 +364,31 @@ impl<'a> Monster<'a> {
#[inline]
pub fn pos(&self) -> Option<&'a Vec3> {
self._tab.get::<Vec3>(Monster::VT_POS, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Vec3>(Monster::VT_POS, None)}
}
#[inline]
pub fn mana(&self) -> i16 {
self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()}
}
#[inline]
pub fn hp(&self) -> i16 {
self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()}
}
#[inline]
pub fn name(&self) -> &'a str {
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()}
}
#[inline]
pub fn key_compare_less_than(&self, o: &Monster) -> bool {
@@ -389,220 +401,378 @@ impl<'a> Monster<'a> {
key.cmp(val)
}
#[inline]
pub fn inventory(&self) -> Option<&'a [u8]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None).map(|v| v.safe_slice())
pub fn inventory(&self) -> Option<flatbuffers::Vector<'a, u8>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None)}
}
#[inline]
pub fn color(&self) -> Color {
self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()}
}
#[inline]
pub fn test_type(&self) -> Any {
self._tab.get::<Any>(Monster::VT_TEST_TYPE, Some(Any::NONE)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Any>(Monster::VT_TEST_TYPE, Some(Any::NONE)).unwrap()}
}
#[inline]
pub fn test(&self) -> Option<flatbuffers::Table<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_TEST, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_TEST, None)}
}
#[inline]
pub fn test4(&self) -> Option<&'a [Test]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST4, None).map(|v| v.safe_slice())
pub fn test4(&self) -> Option<flatbuffers::Vector<'a, Test>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST4, None)}
}
#[inline]
pub fn testarrayofstring(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING, None)}
}
/// an example documentation comment: this will end up in the generated code
/// multiline too
#[inline]
pub fn testarrayoftables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster<'a>>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster>>>>(Monster::VT_TESTARRAYOFTABLES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster>>>>(Monster::VT_TESTARRAYOFTABLES, None)}
}
#[inline]
pub fn enemy(&self) -> Option<Monster<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<Monster>>(Monster::VT_ENEMY, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<Monster>>(Monster::VT_ENEMY, None)}
}
#[inline]
pub fn testnestedflatbuffer(&self) -> Option<&'a [u8]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTNESTEDFLATBUFFER, None).map(|v| v.safe_slice())
pub fn testnestedflatbuffer(&self) -> Option<flatbuffers::Vector<'a, u8>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTNESTEDFLATBUFFER, None)}
}
pub fn testnestedflatbuffer_nested_flatbuffer(&'a self) -> Option<Monster<'a>> {
self.testnestedflatbuffer().map(|data| {
use flatbuffers::Follow;
<flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data, 0)
// Safety:
// Created from a valid Table for this object
// Which contains a valid flatbuffer in this slot
unsafe { <flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data.bytes(), 0) }
})
}
#[inline]
pub fn testempty(&self) -> Option<Stat<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<Stat>>(Monster::VT_TESTEMPTY, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<Stat>>(Monster::VT_TESTEMPTY, None)}
}
#[inline]
pub fn testbool(&self) -> bool {
self._tab.get::<bool>(Monster::VT_TESTBOOL, Some(false)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<bool>(Monster::VT_TESTBOOL, Some(false)).unwrap()}
}
#[inline]
pub fn testhashs32_fnv1(&self) -> i32 {
self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1, Some(0)).unwrap()}
}
#[inline]
pub fn testhashu32_fnv1(&self) -> u32 {
self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1, Some(0)).unwrap()}
}
#[inline]
pub fn testhashs64_fnv1(&self) -> i64 {
self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1, Some(0)).unwrap()}
}
#[inline]
pub fn testhashu64_fnv1(&self) -> u64 {
self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1, Some(0)).unwrap()}
}
#[inline]
pub fn testhashs32_fnv1a(&self) -> i32 {
self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1A, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1A, Some(0)).unwrap()}
}
#[inline]
pub fn testhashu32_fnv1a(&self) -> u32 {
self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1A, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1A, Some(0)).unwrap()}
}
#[inline]
pub fn testhashs64_fnv1a(&self) -> i64 {
self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1A, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1A, Some(0)).unwrap()}
}
#[inline]
pub fn testhashu64_fnv1a(&self) -> u64 {
self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1A, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1A, Some(0)).unwrap()}
}
#[inline]
pub fn testarrayofbools(&self) -> Option<&'a [bool]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(Monster::VT_TESTARRAYOFBOOLS, None).map(|v| v.safe_slice())
pub fn testarrayofbools(&self) -> Option<flatbuffers::Vector<'a, bool>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(Monster::VT_TESTARRAYOFBOOLS, None)}
}
#[inline]
pub fn testf(&self) -> f32 {
self._tab.get::<f32>(Monster::VT_TESTF, Some(3.14159)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(Monster::VT_TESTF, Some(3.14159)).unwrap()}
}
#[inline]
pub fn testf2(&self) -> f32 {
self._tab.get::<f32>(Monster::VT_TESTF2, Some(3.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(Monster::VT_TESTF2, Some(3.0)).unwrap()}
}
#[inline]
pub fn testf3(&self) -> f32 {
self._tab.get::<f32>(Monster::VT_TESTF3, Some(0.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(Monster::VT_TESTF3, Some(0.0)).unwrap()}
}
#[inline]
pub fn testarrayofstring2(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING2, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING2, None)}
}
#[inline]
pub fn testarrayofsortedstruct(&self) -> Option<&'a [Ability]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Ability>>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, None).map(|v| v.safe_slice())
pub fn testarrayofsortedstruct(&self) -> Option<flatbuffers::Vector<'a, Ability>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Ability>>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, None)}
}
#[inline]
pub fn flex(&self) -> Option<&'a [u8]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_FLEX, None).map(|v| v.safe_slice())
pub fn flex(&self) -> Option<flatbuffers::Vector<'a, u8>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_FLEX, None)}
}
#[inline]
pub fn test5(&self) -> Option<&'a [Test]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST5, None).map(|v| v.safe_slice())
pub fn test5(&self) -> Option<flatbuffers::Vector<'a, Test>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST5, None)}
}
#[inline]
pub fn vector_of_longs(&self) -> Option<flatbuffers::Vector<'a, i64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(Monster::VT_VECTOR_OF_LONGS, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(Monster::VT_VECTOR_OF_LONGS, None)}
}
#[inline]
pub fn vector_of_doubles(&self) -> Option<flatbuffers::Vector<'a, f64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(Monster::VT_VECTOR_OF_DOUBLES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(Monster::VT_VECTOR_OF_DOUBLES, None)}
}
#[inline]
pub fn parent_namespace_test(&self) -> Option<super::InParentNamespace<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<super::InParentNamespace>>(Monster::VT_PARENT_NAMESPACE_TEST, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::InParentNamespace>>(Monster::VT_PARENT_NAMESPACE_TEST, None)}
}
#[inline]
pub fn vector_of_referrables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable<'a>>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_REFERRABLES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_REFERRABLES, None)}
}
#[inline]
pub fn single_weak_reference(&self) -> u64 {
self._tab.get::<u64>(Monster::VT_SINGLE_WEAK_REFERENCE, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Monster::VT_SINGLE_WEAK_REFERENCE, Some(0)).unwrap()}
}
#[inline]
pub fn vector_of_weak_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, None)}
}
#[inline]
pub fn vector_of_strong_referrables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable<'a>>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, None)}
}
#[inline]
pub fn co_owning_reference(&self) -> u64 {
self._tab.get::<u64>(Monster::VT_CO_OWNING_REFERENCE, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Monster::VT_CO_OWNING_REFERENCE, Some(0)).unwrap()}
}
#[inline]
pub fn vector_of_co_owning_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, None)}
}
#[inline]
pub fn non_owning_reference(&self) -> u64 {
self._tab.get::<u64>(Monster::VT_NON_OWNING_REFERENCE, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Monster::VT_NON_OWNING_REFERENCE, Some(0)).unwrap()}
}
#[inline]
pub fn vector_of_non_owning_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, None)}
}
#[inline]
pub fn any_unique_type(&self) -> AnyUniqueAliases {
self._tab.get::<AnyUniqueAliases>(Monster::VT_ANY_UNIQUE_TYPE, Some(AnyUniqueAliases::NONE)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<AnyUniqueAliases>(Monster::VT_ANY_UNIQUE_TYPE, Some(AnyUniqueAliases::NONE)).unwrap()}
}
#[inline]
pub fn any_unique(&self) -> Option<flatbuffers::Table<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_UNIQUE, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_UNIQUE, None)}
}
#[inline]
pub fn any_ambiguous_type(&self) -> AnyAmbiguousAliases {
self._tab.get::<AnyAmbiguousAliases>(Monster::VT_ANY_AMBIGUOUS_TYPE, Some(AnyAmbiguousAliases::NONE)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<AnyAmbiguousAliases>(Monster::VT_ANY_AMBIGUOUS_TYPE, Some(AnyAmbiguousAliases::NONE)).unwrap()}
}
#[inline]
pub fn any_ambiguous(&self) -> Option<flatbuffers::Table<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_AMBIGUOUS, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_AMBIGUOUS, None)}
}
#[inline]
pub fn vector_of_enums(&self) -> Option<flatbuffers::Vector<'a, Color>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)}
}
#[inline]
pub fn signed_enum(&self) -> Race {
self._tab.get::<Race>(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Race>(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()}
}
#[inline]
pub fn testrequirednestedflatbuffer(&self) -> Option<&'a [u8]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, None).map(|v| v.safe_slice())
pub fn testrequirednestedflatbuffer(&self) -> Option<flatbuffers::Vector<'a, u8>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, None)}
}
pub fn testrequirednestedflatbuffer_nested_flatbuffer(&'a self) -> Option<Monster<'a>> {
self.testrequirednestedflatbuffer().map(|data| {
use flatbuffers::Follow;
<flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data, 0)
// Safety:
// Created from a valid Table for this object
// Which contains a valid flatbuffer in this slot
unsafe { <flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data.bytes(), 0) }
})
}
#[inline]
pub fn scalar_key_sorted_tables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat<'a>>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat>>>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat>>>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, None)}
}
#[inline]
pub fn native_inline(&self) -> Option<&'a Test> {
self._tab.get::<Test>(Monster::VT_NATIVE_INLINE, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Test>(Monster::VT_NATIVE_INLINE, None)}
}
#[inline]
pub fn long_enum_non_enum_default(&self) -> LongEnum {
self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, Some(Default::default())).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, Some(Default::default())).unwrap()}
}
#[inline]
pub fn long_enum_normal_default(&self) -> LongEnum {
self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, Some(LongEnum::LongOne)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, Some(LongEnum::LongOne)).unwrap()}
}
#[inline]
#[allow(non_snake_case)]
pub fn test_as_monster(&self) -> Option<Monster<'a>> {
if self.test_type() == Any::Monster {
self.test().map(Monster::init_from_table)
self.test().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { Monster::init_from_table(t) }
})
} else {
None
}
@@ -612,7 +782,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn test_as_test_simple_table_with_enum(&self) -> Option<TestSimpleTableWithEnum<'a>> {
if self.test_type() == Any::TestSimpleTableWithEnum {
self.test().map(TestSimpleTableWithEnum::init_from_table)
self.test().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { TestSimpleTableWithEnum::init_from_table(t) }
})
} else {
None
}
@@ -622,7 +797,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn test_as_my_game_example_2_monster(&self) -> Option<super::example_2::Monster<'a>> {
if self.test_type() == Any::MyGame_Example2_Monster {
self.test().map(super::example_2::Monster::init_from_table)
self.test().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { super::example_2::Monster::init_from_table(t) }
})
} else {
None
}
@@ -632,7 +812,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_unique_as_m(&self) -> Option<Monster<'a>> {
if self.any_unique_type() == AnyUniqueAliases::M {
self.any_unique().map(Monster::init_from_table)
self.any_unique().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { Monster::init_from_table(t) }
})
} else {
None
}
@@ -642,7 +827,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_unique_as_ts(&self) -> Option<TestSimpleTableWithEnum<'a>> {
if self.any_unique_type() == AnyUniqueAliases::TS {
self.any_unique().map(TestSimpleTableWithEnum::init_from_table)
self.any_unique().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { TestSimpleTableWithEnum::init_from_table(t) }
})
} else {
None
}
@@ -652,7 +842,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_unique_as_m2(&self) -> Option<super::example_2::Monster<'a>> {
if self.any_unique_type() == AnyUniqueAliases::M2 {
self.any_unique().map(super::example_2::Monster::init_from_table)
self.any_unique().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { super::example_2::Monster::init_from_table(t) }
})
} else {
None
}
@@ -662,7 +857,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_ambiguous_as_m1(&self) -> Option<Monster<'a>> {
if self.any_ambiguous_type() == AnyAmbiguousAliases::M1 {
self.any_ambiguous().map(Monster::init_from_table)
self.any_ambiguous().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { Monster::init_from_table(t) }
})
} else {
None
}
@@ -672,7 +872,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_ambiguous_as_m2(&self) -> Option<Monster<'a>> {
if self.any_ambiguous_type() == AnyAmbiguousAliases::M2 {
self.any_ambiguous().map(Monster::init_from_table)
self.any_ambiguous().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { Monster::init_from_table(t) }
})
} else {
None
}
@@ -682,7 +887,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_ambiguous_as_m3(&self) -> Option<Monster<'a>> {
if self.any_ambiguous_type() == AnyAmbiguousAliases::M3 {
self.any_ambiguous().map(Monster::init_from_table)
self.any_ambiguous().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { Monster::init_from_table(t) }
})
} else {
None
}
@@ -1391,7 +1601,7 @@ impl MonsterT {
let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
});
let testarrayofstring = self.testarrayofstring.as_ref().map(|x|{
let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();_fbb.create_vector_of_strings(&w)
let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w)
});
let testarrayoftables = self.testarrayoftables.as_ref().map(|x|{
let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
@@ -1421,7 +1631,7 @@ impl MonsterT {
let testf2 = self.testf2;
let testf3 = self.testf3;
let testarrayofstring2 = self.testarrayofstring2.as_ref().map(|x|{
let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();_fbb.create_vector_of_strings(&w)
let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w)
});
let testarrayofsortedstruct = self.testarrayofsortedstruct.as_ref().map(|x|{
let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
@@ -1534,18 +1744,6 @@ impl MonsterT {
})
}
}
#[inline]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
unsafe { flatbuffers::root_unchecked::<Monster<'a>>(buf) }
}
#[inline]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
unsafe { flatbuffers::size_prefixed_root_unchecked::<Monster<'a>>(buf) }
}
#[inline]
/// Verifies that a buffer of bytes contains a `Monster`
/// and returns it.

View File

@@ -63,10 +63,8 @@ impl core::fmt::Debug for Race {
impl<'a> flatbuffers::Follow<'a> for Race {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
Self(b)
}
}
@@ -74,21 +72,21 @@ impl<'a> flatbuffers::Follow<'a> for Race {
impl flatbuffers::Push for Race {
type Output = Race;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for Race {
type Scalar = i8;
#[inline]
fn to_little_endian(self) -> Self {
let b = i8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i8::from_le(self.0);
fn from_little_endian(v: i8) -> Self {
let b = i8::from_le(v);
Self(b)
}
}

View File

@@ -19,8 +19,8 @@ pub struct Referrable<'a> {
impl<'a> flatbuffers::Follow<'a> for Referrable<'a> {
type Inner = Referrable<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> Referrable<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
Referrable { _tab: table }
}
#[allow(unused_mut)]
@@ -54,7 +54,10 @@ impl<'a> Referrable<'a> {
#[inline]
pub fn id(&self) -> u64 {
self._tab.get::<u64>(Referrable::VT_ID, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Referrable::VT_ID, Some(0)).unwrap()}
}
#[inline]
pub fn key_compare_less_than(&self, o: &Referrable) -> bool {

View File

@@ -19,8 +19,8 @@ pub struct Stat<'a> {
impl<'a> flatbuffers::Follow<'a> for Stat<'a> {
type Inner = Stat<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -34,7 +34,7 @@ impl<'a> Stat<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
Stat { _tab: table }
}
#[allow(unused_mut)]
@@ -64,15 +64,24 @@ impl<'a> Stat<'a> {
#[inline]
pub fn id(&self) -> Option<&'a str> {
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)}
}
#[inline]
pub fn val(&self) -> i64 {
self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap()}
}
#[inline]
pub fn count(&self) -> u16 {
self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()}
}
#[inline]
pub fn key_compare_less_than(&self, o: &Stat) -> bool {

View File

@@ -29,39 +29,25 @@ impl core::fmt::Debug for StructOfStructs {
}
impl flatbuffers::SimpleToVerifyInSlice for StructOfStructs {}
impl flatbuffers::SafeSliceAccess for StructOfStructs {}
impl<'a> flatbuffers::Follow<'a> for StructOfStructs {
type Inner = &'a StructOfStructs;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a StructOfStructs>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a StructOfStructs {
type Inner = &'a StructOfStructs;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<StructOfStructs>(buf, loc)
}
}
impl<'b> flatbuffers::Push for StructOfStructs {
type Output = StructOfStructs;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b StructOfStructs {
type Output = StructOfStructs;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const StructOfStructs as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -95,6 +81,9 @@ impl<'a> StructOfStructs {
}
pub fn a(&self) -> &Ability {
// Safety:
// Created from a valid Table for this object
// Which contains a valid struct in this slot
unsafe { &*(self.0[0..].as_ptr() as *const Ability) }
}
@@ -104,6 +93,9 @@ impl<'a> StructOfStructs {
}
pub fn b(&self) -> &Test {
// Safety:
// Created from a valid Table for this object
// Which contains a valid struct in this slot
unsafe { &*(self.0[8..].as_ptr() as *const Test) }
}
@@ -113,6 +105,9 @@ impl<'a> StructOfStructs {
}
pub fn c(&self) -> &Ability {
// Safety:
// Created from a valid Table for this object
// Which contains a valid struct in this slot
unsafe { &*(self.0[12..].as_ptr() as *const Ability) }
}

View File

@@ -27,39 +27,25 @@ impl core::fmt::Debug for StructOfStructsOfStructs {
}
impl flatbuffers::SimpleToVerifyInSlice for StructOfStructsOfStructs {}
impl flatbuffers::SafeSliceAccess for StructOfStructsOfStructs {}
impl<'a> flatbuffers::Follow<'a> for StructOfStructsOfStructs {
type Inner = &'a StructOfStructsOfStructs;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a StructOfStructsOfStructs>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a StructOfStructsOfStructs {
type Inner = &'a StructOfStructsOfStructs;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<StructOfStructsOfStructs>(buf, loc)
}
}
impl<'b> flatbuffers::Push for StructOfStructsOfStructs {
type Output = StructOfStructsOfStructs;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b StructOfStructsOfStructs {
type Output = StructOfStructsOfStructs;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const StructOfStructsOfStructs as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -89,6 +75,9 @@ impl<'a> StructOfStructsOfStructs {
}
pub fn a(&self) -> &StructOfStructs {
// Safety:
// Created from a valid Table for this object
// Which contains a valid struct in this slot
unsafe { &*(self.0[0..].as_ptr() as *const StructOfStructs) }
}

View File

@@ -28,39 +28,25 @@ impl core::fmt::Debug for Test {
}
impl flatbuffers::SimpleToVerifyInSlice for Test {}
impl flatbuffers::SafeSliceAccess for Test {}
impl<'a> flatbuffers::Follow<'a> for Test {
type Inner = &'a Test;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Test>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Test {
type Inner = &'a Test;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Test>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Test {
type Output = Test;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Test {
type Output = Test;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Test as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -92,47 +78,59 @@ impl<'a> Test {
}
pub fn a(&self) -> i16 {
let mut mem = core::mem::MaybeUninit::<i16>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i16 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::<i16>(),
core::mem::size_of::<<i16 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_a(&mut self, x: i16) {
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 i16 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<i16>(),
core::mem::size_of::<<i16 as EndianScalar>::Scalar>(),
);
}
}
pub fn b(&self) -> i8 {
let mut mem = core::mem::MaybeUninit::<i8>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i8 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[2..].as_ptr(),
mem.as_mut_ptr() as *mut u8,
core::mem::size_of::<i8>(),
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_b(&mut self, x: i8) {
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 i8 as *const u8,
&x_le as *const _ as *const u8,
self.0[2..].as_mut_ptr(),
core::mem::size_of::<i8>(),
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
);
}
}

View File

@@ -19,8 +19,8 @@ pub struct TestSimpleTableWithEnum<'a> {
impl<'a> flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> {
type Inner = TestSimpleTableWithEnum<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> TestSimpleTableWithEnum<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TestSimpleTableWithEnum { _tab: table }
}
#[allow(unused_mut)]
@@ -54,7 +54,10 @@ impl<'a> TestSimpleTableWithEnum<'a> {
#[inline]
pub fn color(&self) -> Color {
self._tab.get::<Color>(TestSimpleTableWithEnum::VT_COLOR, Some(Color::Green)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Color>(TestSimpleTableWithEnum::VT_COLOR, Some(Color::Green)).unwrap()}
}
}

View File

@@ -19,8 +19,8 @@ pub struct TypeAliases<'a> {
impl<'a> flatbuffers::Follow<'a> for TypeAliases<'a> {
type Inner = TypeAliases<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -43,7 +43,7 @@ impl<'a> TypeAliases<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TypeAliases { _tab: table }
}
#[allow(unused_mut)]
@@ -79,7 +79,7 @@ impl<'a> TypeAliases<'a> {
let f32_ = self.f32_();
let f64_ = self.f64_();
let v8 = self.v8().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let vf64 = self.vf64().map(|x| {
x.into_iter().collect()
@@ -102,51 +102,87 @@ impl<'a> TypeAliases<'a> {
#[inline]
pub fn i8_(&self) -> i8 {
self._tab.get::<i8>(TypeAliases::VT_I8_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i8>(TypeAliases::VT_I8_, Some(0)).unwrap()}
}
#[inline]
pub fn u8_(&self) -> u8 {
self._tab.get::<u8>(TypeAliases::VT_U8_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u8>(TypeAliases::VT_U8_, Some(0)).unwrap()}
}
#[inline]
pub fn i16_(&self) -> i16 {
self._tab.get::<i16>(TypeAliases::VT_I16_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i16>(TypeAliases::VT_I16_, Some(0)).unwrap()}
}
#[inline]
pub fn u16_(&self) -> u16 {
self._tab.get::<u16>(TypeAliases::VT_U16_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u16>(TypeAliases::VT_U16_, Some(0)).unwrap()}
}
#[inline]
pub fn i32_(&self) -> i32 {
self._tab.get::<i32>(TypeAliases::VT_I32_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(TypeAliases::VT_I32_, Some(0)).unwrap()}
}
#[inline]
pub fn u32_(&self) -> u32 {
self._tab.get::<u32>(TypeAliases::VT_U32_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u32>(TypeAliases::VT_U32_, Some(0)).unwrap()}
}
#[inline]
pub fn i64_(&self) -> i64 {
self._tab.get::<i64>(TypeAliases::VT_I64_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(TypeAliases::VT_I64_, Some(0)).unwrap()}
}
#[inline]
pub fn u64_(&self) -> u64 {
self._tab.get::<u64>(TypeAliases::VT_U64_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(TypeAliases::VT_U64_, Some(0)).unwrap()}
}
#[inline]
pub fn f32_(&self) -> f32 {
self._tab.get::<f32>(TypeAliases::VT_F32_, Some(0.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(TypeAliases::VT_F32_, Some(0.0)).unwrap()}
}
#[inline]
pub fn f64_(&self) -> f64 {
self._tab.get::<f64>(TypeAliases::VT_F64_, Some(0.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f64>(TypeAliases::VT_F64_, Some(0.0)).unwrap()}
}
#[inline]
pub fn v8(&self) -> Option<&'a [i8]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i8>>>(TypeAliases::VT_V8, None).map(|v| v.safe_slice())
pub fn v8(&self) -> Option<flatbuffers::Vector<'a, i8>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i8>>>(TypeAliases::VT_V8, None)}
}
#[inline]
pub fn vf64(&self) -> Option<flatbuffers::Vector<'a, f64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(TypeAliases::VT_VF64, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(TypeAliases::VT_VF64, None)}
}
}

View File

@@ -32,39 +32,25 @@ impl core::fmt::Debug for Vec3 {
}
impl flatbuffers::SimpleToVerifyInSlice for Vec3 {}
impl flatbuffers::SafeSliceAccess for Vec3 {}
impl<'a> flatbuffers::Follow<'a> for Vec3 {
type Inner = &'a Vec3;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Vec3>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
type Inner = &'a Vec3;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Vec3 {
type Output = Vec3;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Vec3 {
type Output = Vec3;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -104,121 +90,154 @@ impl<'a> Vec3 {
}
pub fn x(&self) -> f32 {
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
unsafe {
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>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_x(&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 f32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<f32>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
}
}
pub fn y(&self) -> f32 {
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
unsafe {
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>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_y(&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 f32 as *const u8,
&x_le as *const _ as *const u8,
self.0[4..].as_mut_ptr(),
core::mem::size_of::<f32>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
}
}
pub fn z(&self) -> f32 {
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
unsafe {
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>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_z(&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 f32 as *const u8,
&x_le as *const _ as *const u8,
self.0[8..].as_mut_ptr(),
core::mem::size_of::<f32>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
}
}
pub fn test1(&self) -> f64 {
let mut mem = core::mem::MaybeUninit::<f64>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<f64 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[16..].as_ptr(),
mem.as_mut_ptr() as *mut u8,
core::mem::size_of::<f64>(),
core::mem::size_of::<<f64 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_test1(&mut self, x: f64) {
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 f64 as *const u8,
&x_le as *const _ as *const u8,
self.0[16..].as_mut_ptr(),
core::mem::size_of::<f64>(),
core::mem::size_of::<<f64 as EndianScalar>::Scalar>(),
);
}
}
pub fn test2(&self) -> Color {
let mut mem = core::mem::MaybeUninit::<Color>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<Color 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[24..].as_ptr(),
mem.as_mut_ptr() as *mut u8,
core::mem::size_of::<Color>(),
core::mem::size_of::<<Color as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_test2(&mut self, x: Color) {
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 Color as *const u8,
&x_le as *const _ as *const u8,
self.0[24..].as_mut_ptr(),
core::mem::size_of::<Color>(),
core::mem::size_of::<<Color as EndianScalar>::Scalar>(),
);
}
}
pub fn test3(&self) -> &Test {
// Safety:
// Created from a valid Table for this object
// Which contains a valid struct in this slot
unsafe { &*(self.0[26..].as_ptr() as *const Test) }
}

View File

@@ -19,8 +19,8 @@ pub struct Monster<'a> {
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
type Inner = Monster<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -31,7 +31,7 @@ impl<'a> Monster<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
Monster { _tab: table }
}
#[allow(unused_mut)]

View File

@@ -19,8 +19,8 @@ pub struct InParentNamespace<'a> {
impl<'a> flatbuffers::Follow<'a> for InParentNamespace<'a> {
type Inner = InParentNamespace<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -31,7 +31,7 @@ impl<'a> InParentNamespace<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
InParentNamespace { _tab: table }
}
#[allow(unused_mut)]

View File

@@ -51,10 +51,8 @@ impl core::fmt::Debug for FromInclude {
impl<'a> flatbuffers::Follow<'a> for FromInclude {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i64>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
Self(b)
}
}
@@ -62,21 +60,21 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
impl flatbuffers::Push for FromInclude {
type Output = FromInclude;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i64>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i64>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for FromInclude {
type Scalar = i64;
#[inline]
fn to_little_endian(self) -> Self {
let b = i64::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i64 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i64::from_le(self.0);
fn from_little_endian(v: i64) -> Self {
let b = i64::from_le(v);
Self(b)
}
}

View File

@@ -19,8 +19,8 @@ pub struct TableB<'a> {
impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
type Inner = TableB<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> TableB<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableB { _tab: table }
}
#[allow(unused_mut)]
@@ -56,7 +56,10 @@ impl<'a> TableB<'a> {
#[inline]
pub fn a(&self) -> Option<super::super::TableA<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)}
}
}

View File

@@ -27,39 +27,25 @@ impl core::fmt::Debug for Unused {
}
impl flatbuffers::SimpleToVerifyInSlice for Unused {}
impl flatbuffers::SafeSliceAccess for Unused {}
impl<'a> flatbuffers::Follow<'a> for Unused {
type Inner = &'a Unused;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Unused>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Unused {
type Inner = &'a Unused;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Unused>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Unused {
type Output = Unused;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Unused {
type Output = Unused;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -89,24 +75,30 @@ impl<'a> Unused {
}
pub fn a(&self) -> i32 {
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i32 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::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_a(&mut self, x: i32) {
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 i32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
}
}

View File

@@ -19,8 +19,8 @@ pub struct TableA<'a> {
impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
type Inner = TableA<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> TableA<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableA { _tab: table }
}
#[allow(unused_mut)]
@@ -56,7 +56,10 @@ impl<'a> TableA<'a> {
#[inline]
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
}
}

View File

@@ -30,39 +30,25 @@ impl core::fmt::Debug for Ability {
}
impl flatbuffers::SimpleToVerifyInSlice for Ability {}
impl flatbuffers::SafeSliceAccess for Ability {}
impl<'a> flatbuffers::Follow<'a> for Ability {
type Inner = &'a Ability;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Ability>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Ability {
type Inner = &'a Ability;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Ability>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Ability {
type Output = Ability;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Ability {
type Output = Ability;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Ability as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -106,24 +92,30 @@ impl<'a> Ability {
}
pub fn id(&self) -> u32 {
let mut mem = core::mem::MaybeUninit::<u32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<u32 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::<u32>(),
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_id(&mut self, x: u32) {
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 u32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<u32>(),
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
);
}
}
@@ -139,24 +131,30 @@ impl<'a> Ability {
key.cmp(&val)
}
pub fn distance(&self) -> u32 {
let mut mem = core::mem::MaybeUninit::<u32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<u32 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::<u32>(),
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_distance(&mut self, x: u32) {
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 u32 as *const u8,
&x_le as *const _ as *const u8,
self.0[4..].as_mut_ptr(),
core::mem::size_of::<u32>(),
core::mem::size_of::<<u32 as EndianScalar>::Scalar>(),
);
}
}

View File

@@ -74,10 +74,8 @@ impl Serialize for AnyAmbiguousAliases {
impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
Self(b)
}
}
@@ -85,21 +83,21 @@ impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
impl flatbuffers::Push for AnyAmbiguousAliases {
type Output = AnyAmbiguousAliases;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for AnyAmbiguousAliases {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> u8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.0);
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
Self(b)
}
}

View File

@@ -74,10 +74,8 @@ impl Serialize for Any {
impl<'a> flatbuffers::Follow<'a> for Any {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
Self(b)
}
}
@@ -85,21 +83,21 @@ impl<'a> flatbuffers::Follow<'a> for Any {
impl flatbuffers::Push for Any {
type Output = Any;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for Any {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> u8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.0);
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
Self(b)
}
}

View File

@@ -74,10 +74,8 @@ impl Serialize for AnyUniqueAliases {
impl<'a> flatbuffers::Follow<'a> for AnyUniqueAliases {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
Self(b)
}
}
@@ -85,21 +83,21 @@ impl<'a> flatbuffers::Follow<'a> for AnyUniqueAliases {
impl flatbuffers::Push for AnyUniqueAliases {
type Output = AnyUniqueAliases;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for AnyUniqueAliases {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> u8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.0);
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
Self(b)
}
}

View File

@@ -40,32 +40,38 @@ impl Serialize for Color {
impl<'a> flatbuffers::Follow<'a> for Color {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe { Self::from_bits_unchecked(b) }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
// Safety:
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
// https://github.com/bitflags/bitflags/issues/262
Self::from_bits_unchecked(b)
}
}
impl flatbuffers::Push for Color {
type Output = Color;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.bits()); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.bits());
}
}
impl flatbuffers::EndianScalar for Color {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.bits());
unsafe { Self::from_bits_unchecked(b) }
fn to_little_endian(self) -> u8 {
self.bits().to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.bits());
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
// Safety:
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
// https://github.com/bitflags/bitflags/issues/262
unsafe { Self::from_bits_unchecked(b) }
}
}

View File

@@ -36,32 +36,38 @@ impl Serialize for LongEnum {
impl<'a> flatbuffers::Follow<'a> for LongEnum {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u64>(buf, loc)
};
unsafe { Self::from_bits_unchecked(b) }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u64>(buf, loc);
// Safety:
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
// https://github.com/bitflags/bitflags/issues/262
Self::from_bits_unchecked(b)
}
}
impl flatbuffers::Push for LongEnum {
type Output = LongEnum;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u64>(dst, self.bits()); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u64>(dst, self.bits());
}
}
impl flatbuffers::EndianScalar for LongEnum {
type Scalar = u64;
#[inline]
fn to_little_endian(self) -> Self {
let b = u64::to_le(self.bits());
unsafe { Self::from_bits_unchecked(b) }
fn to_little_endian(self) -> u64 {
self.bits().to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u64::from_le(self.bits());
fn from_little_endian(v: u64) -> Self {
let b = u64::from_le(v);
// Safety:
// This is safe because we know bitflags is implemented with a repr transparent uint of the correct size.
// from_bits_unchecked will be replaced by an equivalent but safe from_bits_retain in bitflags 2.0
// https://github.com/bitflags/bitflags/issues/262
unsafe { Self::from_bits_unchecked(b) }
}
}

View File

@@ -22,8 +22,8 @@ pub struct Monster<'a> {
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
type Inner = Monster<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -87,7 +87,7 @@ impl<'a> Monster<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
Monster { _tab: table }
}
#[allow(unused_mut)]
@@ -163,7 +163,7 @@ impl<'a> Monster<'a> {
x.to_string()
};
let inventory = self.inventory().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let color = self.color();
let test = match self.test_type() {
@@ -198,7 +198,7 @@ impl<'a> Monster<'a> {
Box::new(x.unpack())
});
let testnestedflatbuffer = self.testnestedflatbuffer().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let testempty = self.testempty().map(|x| {
Box::new(x.unpack())
@@ -213,7 +213,7 @@ impl<'a> Monster<'a> {
let testhashs64_fnv1a = self.testhashs64_fnv1a();
let testhashu64_fnv1a = self.testhashu64_fnv1a();
let testarrayofbools = self.testarrayofbools().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let testf = self.testf();
let testf2 = self.testf2();
@@ -225,7 +225,7 @@ impl<'a> Monster<'a> {
x.iter().map(|t| t.unpack()).collect()
});
let flex = self.flex().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let test5 = self.test5().map(|x| {
x.iter().map(|t| t.unpack()).collect()
@@ -300,7 +300,7 @@ impl<'a> Monster<'a> {
});
let signed_enum = self.signed_enum();
let testrequirednestedflatbuffer = self.testrequirednestedflatbuffer().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let scalar_key_sorted_tables = self.scalar_key_sorted_tables().map(|x| {
x.iter().map(|t| t.unpack()).collect()
@@ -366,19 +366,31 @@ impl<'a> Monster<'a> {
#[inline]
pub fn pos(&self) -> Option<&'a Vec3> {
self._tab.get::<Vec3>(Monster::VT_POS, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Vec3>(Monster::VT_POS, None)}
}
#[inline]
pub fn mana(&self) -> i16 {
self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()}
}
#[inline]
pub fn hp(&self) -> i16 {
self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()}
}
#[inline]
pub fn name(&self) -> &'a str {
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None).unwrap()}
}
#[inline]
pub fn key_compare_less_than(&self, o: &Monster) -> bool {
@@ -391,220 +403,378 @@ impl<'a> Monster<'a> {
key.cmp(val)
}
#[inline]
pub fn inventory(&self) -> Option<&'a [u8]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None).map(|v| v.safe_slice())
pub fn inventory(&self) -> Option<flatbuffers::Vector<'a, u8>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None)}
}
#[inline]
pub fn color(&self) -> Color {
self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()}
}
#[inline]
pub fn test_type(&self) -> Any {
self._tab.get::<Any>(Monster::VT_TEST_TYPE, Some(Any::NONE)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Any>(Monster::VT_TEST_TYPE, Some(Any::NONE)).unwrap()}
}
#[inline]
pub fn test(&self) -> Option<flatbuffers::Table<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_TEST, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_TEST, None)}
}
#[inline]
pub fn test4(&self) -> Option<&'a [Test]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST4, None).map(|v| v.safe_slice())
pub fn test4(&self) -> Option<flatbuffers::Vector<'a, Test>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST4, None)}
}
#[inline]
pub fn testarrayofstring(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING, None)}
}
/// an example documentation comment: this will end up in the generated code
/// multiline too
#[inline]
pub fn testarrayoftables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster<'a>>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster>>>>(Monster::VT_TESTARRAYOFTABLES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Monster>>>>(Monster::VT_TESTARRAYOFTABLES, None)}
}
#[inline]
pub fn enemy(&self) -> Option<Monster<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<Monster>>(Monster::VT_ENEMY, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<Monster>>(Monster::VT_ENEMY, None)}
}
#[inline]
pub fn testnestedflatbuffer(&self) -> Option<&'a [u8]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTNESTEDFLATBUFFER, None).map(|v| v.safe_slice())
pub fn testnestedflatbuffer(&self) -> Option<flatbuffers::Vector<'a, u8>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTNESTEDFLATBUFFER, None)}
}
pub fn testnestedflatbuffer_nested_flatbuffer(&'a self) -> Option<Monster<'a>> {
self.testnestedflatbuffer().map(|data| {
use flatbuffers::Follow;
<flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data, 0)
// Safety:
// Created from a valid Table for this object
// Which contains a valid flatbuffer in this slot
unsafe { <flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data.bytes(), 0) }
})
}
#[inline]
pub fn testempty(&self) -> Option<Stat<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<Stat>>(Monster::VT_TESTEMPTY, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<Stat>>(Monster::VT_TESTEMPTY, None)}
}
#[inline]
pub fn testbool(&self) -> bool {
self._tab.get::<bool>(Monster::VT_TESTBOOL, Some(false)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<bool>(Monster::VT_TESTBOOL, Some(false)).unwrap()}
}
#[inline]
pub fn testhashs32_fnv1(&self) -> i32 {
self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1, Some(0)).unwrap()}
}
#[inline]
pub fn testhashu32_fnv1(&self) -> u32 {
self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1, Some(0)).unwrap()}
}
#[inline]
pub fn testhashs64_fnv1(&self) -> i64 {
self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1, Some(0)).unwrap()}
}
#[inline]
pub fn testhashu64_fnv1(&self) -> u64 {
self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1, Some(0)).unwrap()}
}
#[inline]
pub fn testhashs32_fnv1a(&self) -> i32 {
self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1A, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(Monster::VT_TESTHASHS32_FNV1A, Some(0)).unwrap()}
}
#[inline]
pub fn testhashu32_fnv1a(&self) -> u32 {
self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1A, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u32>(Monster::VT_TESTHASHU32_FNV1A, Some(0)).unwrap()}
}
#[inline]
pub fn testhashs64_fnv1a(&self) -> i64 {
self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1A, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(Monster::VT_TESTHASHS64_FNV1A, Some(0)).unwrap()}
}
#[inline]
pub fn testhashu64_fnv1a(&self) -> u64 {
self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1A, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Monster::VT_TESTHASHU64_FNV1A, Some(0)).unwrap()}
}
#[inline]
pub fn testarrayofbools(&self) -> Option<&'a [bool]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(Monster::VT_TESTARRAYOFBOOLS, None).map(|v| v.safe_slice())
pub fn testarrayofbools(&self) -> Option<flatbuffers::Vector<'a, bool>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(Monster::VT_TESTARRAYOFBOOLS, None)}
}
#[inline]
pub fn testf(&self) -> f32 {
self._tab.get::<f32>(Monster::VT_TESTF, Some(3.14159)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(Monster::VT_TESTF, Some(3.14159)).unwrap()}
}
#[inline]
pub fn testf2(&self) -> f32 {
self._tab.get::<f32>(Monster::VT_TESTF2, Some(3.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(Monster::VT_TESTF2, Some(3.0)).unwrap()}
}
#[inline]
pub fn testf3(&self) -> f32 {
self._tab.get::<f32>(Monster::VT_TESTF3, Some(0.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(Monster::VT_TESTF3, Some(0.0)).unwrap()}
}
#[inline]
pub fn testarrayofstring2(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING2, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<&'a str>>>>(Monster::VT_TESTARRAYOFSTRING2, None)}
}
#[inline]
pub fn testarrayofsortedstruct(&self) -> Option<&'a [Ability]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Ability>>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, None).map(|v| v.safe_slice())
pub fn testarrayofsortedstruct(&self) -> Option<flatbuffers::Vector<'a, Ability>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Ability>>>(Monster::VT_TESTARRAYOFSORTEDSTRUCT, None)}
}
#[inline]
pub fn flex(&self) -> Option<&'a [u8]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_FLEX, None).map(|v| v.safe_slice())
pub fn flex(&self) -> Option<flatbuffers::Vector<'a, u8>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_FLEX, None)}
}
#[inline]
pub fn test5(&self) -> Option<&'a [Test]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST5, None).map(|v| v.safe_slice())
pub fn test5(&self) -> Option<flatbuffers::Vector<'a, Test>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Test>>>(Monster::VT_TEST5, None)}
}
#[inline]
pub fn vector_of_longs(&self) -> Option<flatbuffers::Vector<'a, i64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(Monster::VT_VECTOR_OF_LONGS, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i64>>>(Monster::VT_VECTOR_OF_LONGS, None)}
}
#[inline]
pub fn vector_of_doubles(&self) -> Option<flatbuffers::Vector<'a, f64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(Monster::VT_VECTOR_OF_DOUBLES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(Monster::VT_VECTOR_OF_DOUBLES, None)}
}
#[inline]
pub fn parent_namespace_test(&self) -> Option<super::InParentNamespace<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<super::InParentNamespace>>(Monster::VT_PARENT_NAMESPACE_TEST, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::InParentNamespace>>(Monster::VT_PARENT_NAMESPACE_TEST, None)}
}
#[inline]
pub fn vector_of_referrables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable<'a>>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_REFERRABLES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_REFERRABLES, None)}
}
#[inline]
pub fn single_weak_reference(&self) -> u64 {
self._tab.get::<u64>(Monster::VT_SINGLE_WEAK_REFERENCE, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Monster::VT_SINGLE_WEAK_REFERENCE, Some(0)).unwrap()}
}
#[inline]
pub fn vector_of_weak_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_WEAK_REFERENCES, None)}
}
#[inline]
pub fn vector_of_strong_referrables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable<'a>>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Referrable>>>>(Monster::VT_VECTOR_OF_STRONG_REFERRABLES, None)}
}
#[inline]
pub fn co_owning_reference(&self) -> u64 {
self._tab.get::<u64>(Monster::VT_CO_OWNING_REFERENCE, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Monster::VT_CO_OWNING_REFERENCE, Some(0)).unwrap()}
}
#[inline]
pub fn vector_of_co_owning_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_CO_OWNING_REFERENCES, None)}
}
#[inline]
pub fn non_owning_reference(&self) -> u64 {
self._tab.get::<u64>(Monster::VT_NON_OWNING_REFERENCE, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Monster::VT_NON_OWNING_REFERENCE, Some(0)).unwrap()}
}
#[inline]
pub fn vector_of_non_owning_references(&self) -> Option<flatbuffers::Vector<'a, u64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u64>>>(Monster::VT_VECTOR_OF_NON_OWNING_REFERENCES, None)}
}
#[inline]
pub fn any_unique_type(&self) -> AnyUniqueAliases {
self._tab.get::<AnyUniqueAliases>(Monster::VT_ANY_UNIQUE_TYPE, Some(AnyUniqueAliases::NONE)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<AnyUniqueAliases>(Monster::VT_ANY_UNIQUE_TYPE, Some(AnyUniqueAliases::NONE)).unwrap()}
}
#[inline]
pub fn any_unique(&self) -> Option<flatbuffers::Table<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_UNIQUE, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_UNIQUE, None)}
}
#[inline]
pub fn any_ambiguous_type(&self) -> AnyAmbiguousAliases {
self._tab.get::<AnyAmbiguousAliases>(Monster::VT_ANY_AMBIGUOUS_TYPE, Some(AnyAmbiguousAliases::NONE)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<AnyAmbiguousAliases>(Monster::VT_ANY_AMBIGUOUS_TYPE, Some(AnyAmbiguousAliases::NONE)).unwrap()}
}
#[inline]
pub fn any_ambiguous(&self) -> Option<flatbuffers::Table<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_AMBIGUOUS, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_ANY_AMBIGUOUS, None)}
}
#[inline]
pub fn vector_of_enums(&self) -> Option<flatbuffers::Vector<'a, Color>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)}
}
#[inline]
pub fn signed_enum(&self) -> Race {
self._tab.get::<Race>(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Race>(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()}
}
#[inline]
pub fn testrequirednestedflatbuffer(&self) -> Option<&'a [u8]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, None).map(|v| v.safe_slice())
pub fn testrequirednestedflatbuffer(&self) -> Option<flatbuffers::Vector<'a, u8>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_TESTREQUIREDNESTEDFLATBUFFER, None)}
}
pub fn testrequirednestedflatbuffer_nested_flatbuffer(&'a self) -> Option<Monster<'a>> {
self.testrequirednestedflatbuffer().map(|data| {
use flatbuffers::Follow;
<flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data, 0)
// Safety:
// Created from a valid Table for this object
// Which contains a valid flatbuffer in this slot
unsafe { <flatbuffers::ForwardsUOffset<Monster<'a>>>::follow(data.bytes(), 0) }
})
}
#[inline]
pub fn scalar_key_sorted_tables(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat<'a>>>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat>>>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Stat>>>>(Monster::VT_SCALAR_KEY_SORTED_TABLES, None)}
}
#[inline]
pub fn native_inline(&self) -> Option<&'a Test> {
self._tab.get::<Test>(Monster::VT_NATIVE_INLINE, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Test>(Monster::VT_NATIVE_INLINE, None)}
}
#[inline]
pub fn long_enum_non_enum_default(&self) -> LongEnum {
self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, Some(Default::default())).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NON_ENUM_DEFAULT, Some(Default::default())).unwrap()}
}
#[inline]
pub fn long_enum_normal_default(&self) -> LongEnum {
self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, Some(LongEnum::LongOne)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<LongEnum>(Monster::VT_LONG_ENUM_NORMAL_DEFAULT, Some(LongEnum::LongOne)).unwrap()}
}
#[inline]
#[allow(non_snake_case)]
pub fn test_as_monster(&self) -> Option<Monster<'a>> {
if self.test_type() == Any::Monster {
self.test().map(Monster::init_from_table)
self.test().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { Monster::init_from_table(t) }
})
} else {
None
}
@@ -614,7 +784,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn test_as_test_simple_table_with_enum(&self) -> Option<TestSimpleTableWithEnum<'a>> {
if self.test_type() == Any::TestSimpleTableWithEnum {
self.test().map(TestSimpleTableWithEnum::init_from_table)
self.test().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { TestSimpleTableWithEnum::init_from_table(t) }
})
} else {
None
}
@@ -624,7 +799,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn test_as_my_game_example_2_monster(&self) -> Option<super::example_2::Monster<'a>> {
if self.test_type() == Any::MyGame_Example2_Monster {
self.test().map(super::example_2::Monster::init_from_table)
self.test().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { super::example_2::Monster::init_from_table(t) }
})
} else {
None
}
@@ -634,7 +814,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_unique_as_m(&self) -> Option<Monster<'a>> {
if self.any_unique_type() == AnyUniqueAliases::M {
self.any_unique().map(Monster::init_from_table)
self.any_unique().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { Monster::init_from_table(t) }
})
} else {
None
}
@@ -644,7 +829,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_unique_as_ts(&self) -> Option<TestSimpleTableWithEnum<'a>> {
if self.any_unique_type() == AnyUniqueAliases::TS {
self.any_unique().map(TestSimpleTableWithEnum::init_from_table)
self.any_unique().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { TestSimpleTableWithEnum::init_from_table(t) }
})
} else {
None
}
@@ -654,7 +844,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_unique_as_m2(&self) -> Option<super::example_2::Monster<'a>> {
if self.any_unique_type() == AnyUniqueAliases::M2 {
self.any_unique().map(super::example_2::Monster::init_from_table)
self.any_unique().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { super::example_2::Monster::init_from_table(t) }
})
} else {
None
}
@@ -664,7 +859,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_ambiguous_as_m1(&self) -> Option<Monster<'a>> {
if self.any_ambiguous_type() == AnyAmbiguousAliases::M1 {
self.any_ambiguous().map(Monster::init_from_table)
self.any_ambiguous().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { Monster::init_from_table(t) }
})
} else {
None
}
@@ -674,7 +874,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_ambiguous_as_m2(&self) -> Option<Monster<'a>> {
if self.any_ambiguous_type() == AnyAmbiguousAliases::M2 {
self.any_ambiguous().map(Monster::init_from_table)
self.any_ambiguous().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { Monster::init_from_table(t) }
})
} else {
None
}
@@ -684,7 +889,12 @@ impl<'a> Monster<'a> {
#[allow(non_snake_case)]
pub fn any_ambiguous_as_m3(&self) -> Option<Monster<'a>> {
if self.any_ambiguous_type() == AnyAmbiguousAliases::M3 {
self.any_ambiguous().map(Monster::init_from_table)
self.any_ambiguous().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { Monster::init_from_table(t) }
})
} else {
None
}
@@ -1610,7 +1820,7 @@ impl MonsterT {
let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
});
let testarrayofstring = self.testarrayofstring.as_ref().map(|x|{
let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();_fbb.create_vector_of_strings(&w)
let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w)
});
let testarrayoftables = self.testarrayoftables.as_ref().map(|x|{
let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
@@ -1640,7 +1850,7 @@ impl MonsterT {
let testf2 = self.testf2;
let testf3 = self.testf3;
let testarrayofstring2 = self.testarrayofstring2.as_ref().map(|x|{
let w: Vec<_> = x.iter().map(|s| s.as_ref()).collect();_fbb.create_vector_of_strings(&w)
let w: Vec<_> = x.iter().map(|s| _fbb.create_string(s)).collect();_fbb.create_vector(&w)
});
let testarrayofsortedstruct = self.testarrayofsortedstruct.as_ref().map(|x|{
let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
@@ -1753,18 +1963,6 @@ impl MonsterT {
})
}
}
#[inline]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
unsafe { flatbuffers::root_unchecked::<Monster<'a>>(buf) }
}
#[inline]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
unsafe { flatbuffers::size_prefixed_root_unchecked::<Monster<'a>>(buf) }
}
#[inline]
/// Verifies that a buffer of bytes contains a `Monster`
/// and returns it.

View File

@@ -74,10 +74,8 @@ impl Serialize for Race {
impl<'a> flatbuffers::Follow<'a> for Race {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
Self(b)
}
}
@@ -85,21 +83,21 @@ impl<'a> flatbuffers::Follow<'a> for Race {
impl flatbuffers::Push for Race {
type Output = Race;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for Race {
type Scalar = i8;
#[inline]
fn to_little_endian(self) -> Self {
let b = i8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i8::from_le(self.0);
fn from_little_endian(v: i8) -> Self {
let b = i8::from_le(v);
Self(b)
}
}

View File

@@ -21,8 +21,8 @@ pub struct Referrable<'a> {
impl<'a> flatbuffers::Follow<'a> for Referrable<'a> {
type Inner = Referrable<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -34,7 +34,7 @@ impl<'a> Referrable<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
Referrable { _tab: table }
}
#[allow(unused_mut)]
@@ -56,7 +56,10 @@ impl<'a> Referrable<'a> {
#[inline]
pub fn id(&self) -> u64 {
self._tab.get::<u64>(Referrable::VT_ID, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(Referrable::VT_ID, Some(0)).unwrap()}
}
#[inline]
pub fn key_compare_less_than(&self, o: &Referrable) -> bool {

View File

@@ -21,8 +21,8 @@ pub struct Stat<'a> {
impl<'a> flatbuffers::Follow<'a> for Stat<'a> {
type Inner = Stat<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -36,7 +36,7 @@ impl<'a> Stat<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
Stat { _tab: table }
}
#[allow(unused_mut)]
@@ -66,15 +66,24 @@ impl<'a> Stat<'a> {
#[inline]
pub fn id(&self) -> Option<&'a str> {
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Stat::VT_ID, None)}
}
#[inline]
pub fn val(&self) -> i64 {
self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(Stat::VT_VAL, Some(0)).unwrap()}
}
#[inline]
pub fn count(&self) -> u16 {
self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u16>(Stat::VT_COUNT, Some(0)).unwrap()}
}
#[inline]
pub fn key_compare_less_than(&self, o: &Stat) -> bool {

View File

@@ -31,39 +31,25 @@ impl core::fmt::Debug for StructOfStructs {
}
impl flatbuffers::SimpleToVerifyInSlice for StructOfStructs {}
impl flatbuffers::SafeSliceAccess for StructOfStructs {}
impl<'a> flatbuffers::Follow<'a> for StructOfStructs {
type Inner = &'a StructOfStructs;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a StructOfStructs>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a StructOfStructs {
type Inner = &'a StructOfStructs;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<StructOfStructs>(buf, loc)
}
}
impl<'b> flatbuffers::Push for StructOfStructs {
type Output = StructOfStructs;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b StructOfStructs {
type Output = StructOfStructs;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const StructOfStructs as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -110,6 +96,9 @@ impl<'a> StructOfStructs {
}
pub fn a(&self) -> &Ability {
// Safety:
// Created from a valid Table for this object
// Which contains a valid struct in this slot
unsafe { &*(self.0[0..].as_ptr() as *const Ability) }
}
@@ -119,6 +108,9 @@ impl<'a> StructOfStructs {
}
pub fn b(&self) -> &Test {
// Safety:
// Created from a valid Table for this object
// Which contains a valid struct in this slot
unsafe { &*(self.0[8..].as_ptr() as *const Test) }
}
@@ -128,6 +120,9 @@ impl<'a> StructOfStructs {
}
pub fn c(&self) -> &Ability {
// Safety:
// Created from a valid Table for this object
// Which contains a valid struct in this slot
unsafe { &*(self.0[12..].as_ptr() as *const Ability) }
}

View File

@@ -29,39 +29,25 @@ impl core::fmt::Debug for StructOfStructsOfStructs {
}
impl flatbuffers::SimpleToVerifyInSlice for StructOfStructsOfStructs {}
impl flatbuffers::SafeSliceAccess for StructOfStructsOfStructs {}
impl<'a> flatbuffers::Follow<'a> for StructOfStructsOfStructs {
type Inner = &'a StructOfStructsOfStructs;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a StructOfStructsOfStructs>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a StructOfStructsOfStructs {
type Inner = &'a StructOfStructsOfStructs;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<StructOfStructsOfStructs>(buf, loc)
}
}
impl<'b> flatbuffers::Push for StructOfStructsOfStructs {
type Output = StructOfStructsOfStructs;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const StructOfStructsOfStructs as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b StructOfStructsOfStructs {
type Output = StructOfStructsOfStructs;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const StructOfStructsOfStructs as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -102,6 +88,9 @@ impl<'a> StructOfStructsOfStructs {
}
pub fn a(&self) -> &StructOfStructs {
// Safety:
// Created from a valid Table for this object
// Which contains a valid struct in this slot
unsafe { &*(self.0[0..].as_ptr() as *const StructOfStructs) }
}

View File

@@ -30,39 +30,25 @@ impl core::fmt::Debug for Test {
}
impl flatbuffers::SimpleToVerifyInSlice for Test {}
impl flatbuffers::SafeSliceAccess for Test {}
impl<'a> flatbuffers::Follow<'a> for Test {
type Inner = &'a Test;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Test>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Test {
type Inner = &'a Test;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Test>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Test {
type Output = Test;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Test {
type Output = Test;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Test as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -106,47 +92,59 @@ impl<'a> Test {
}
pub fn a(&self) -> i16 {
let mut mem = core::mem::MaybeUninit::<i16>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i16 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::<i16>(),
core::mem::size_of::<<i16 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_a(&mut self, x: i16) {
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 i16 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<i16>(),
core::mem::size_of::<<i16 as EndianScalar>::Scalar>(),
);
}
}
pub fn b(&self) -> i8 {
let mut mem = core::mem::MaybeUninit::<i8>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i8 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[2..].as_ptr(),
mem.as_mut_ptr() as *mut u8,
core::mem::size_of::<i8>(),
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_b(&mut self, x: i8) {
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 i8 as *const u8,
&x_le as *const _ as *const u8,
self.0[2..].as_mut_ptr(),
core::mem::size_of::<i8>(),
core::mem::size_of::<<i8 as EndianScalar>::Scalar>(),
);
}
}

View File

@@ -21,8 +21,8 @@ pub struct TestSimpleTableWithEnum<'a> {
impl<'a> flatbuffers::Follow<'a> for TestSimpleTableWithEnum<'a> {
type Inner = TestSimpleTableWithEnum<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -34,7 +34,7 @@ impl<'a> TestSimpleTableWithEnum<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TestSimpleTableWithEnum { _tab: table }
}
#[allow(unused_mut)]
@@ -56,7 +56,10 @@ impl<'a> TestSimpleTableWithEnum<'a> {
#[inline]
pub fn color(&self) -> Color {
self._tab.get::<Color>(TestSimpleTableWithEnum::VT_COLOR, Some(Color::Green)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<Color>(TestSimpleTableWithEnum::VT_COLOR, Some(Color::Green)).unwrap()}
}
}

View File

@@ -21,8 +21,8 @@ pub struct TypeAliases<'a> {
impl<'a> flatbuffers::Follow<'a> for TypeAliases<'a> {
type Inner = TypeAliases<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -45,7 +45,7 @@ impl<'a> TypeAliases<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TypeAliases { _tab: table }
}
#[allow(unused_mut)]
@@ -81,7 +81,7 @@ impl<'a> TypeAliases<'a> {
let f32_ = self.f32_();
let f64_ = self.f64_();
let v8 = self.v8().map(|x| {
x.to_vec()
x.into_iter().collect()
});
let vf64 = self.vf64().map(|x| {
x.into_iter().collect()
@@ -104,51 +104,87 @@ impl<'a> TypeAliases<'a> {
#[inline]
pub fn i8_(&self) -> i8 {
self._tab.get::<i8>(TypeAliases::VT_I8_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i8>(TypeAliases::VT_I8_, Some(0)).unwrap()}
}
#[inline]
pub fn u8_(&self) -> u8 {
self._tab.get::<u8>(TypeAliases::VT_U8_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u8>(TypeAliases::VT_U8_, Some(0)).unwrap()}
}
#[inline]
pub fn i16_(&self) -> i16 {
self._tab.get::<i16>(TypeAliases::VT_I16_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i16>(TypeAliases::VT_I16_, Some(0)).unwrap()}
}
#[inline]
pub fn u16_(&self) -> u16 {
self._tab.get::<u16>(TypeAliases::VT_U16_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u16>(TypeAliases::VT_U16_, Some(0)).unwrap()}
}
#[inline]
pub fn i32_(&self) -> i32 {
self._tab.get::<i32>(TypeAliases::VT_I32_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(TypeAliases::VT_I32_, Some(0)).unwrap()}
}
#[inline]
pub fn u32_(&self) -> u32 {
self._tab.get::<u32>(TypeAliases::VT_U32_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u32>(TypeAliases::VT_U32_, Some(0)).unwrap()}
}
#[inline]
pub fn i64_(&self) -> i64 {
self._tab.get::<i64>(TypeAliases::VT_I64_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(TypeAliases::VT_I64_, Some(0)).unwrap()}
}
#[inline]
pub fn u64_(&self) -> u64 {
self._tab.get::<u64>(TypeAliases::VT_U64_, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(TypeAliases::VT_U64_, Some(0)).unwrap()}
}
#[inline]
pub fn f32_(&self) -> f32 {
self._tab.get::<f32>(TypeAliases::VT_F32_, Some(0.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(TypeAliases::VT_F32_, Some(0.0)).unwrap()}
}
#[inline]
pub fn f64_(&self) -> f64 {
self._tab.get::<f64>(TypeAliases::VT_F64_, Some(0.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f64>(TypeAliases::VT_F64_, Some(0.0)).unwrap()}
}
#[inline]
pub fn v8(&self) -> Option<&'a [i8]> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i8>>>(TypeAliases::VT_V8, None).map(|v| v.safe_slice())
pub fn v8(&self) -> Option<flatbuffers::Vector<'a, i8>> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i8>>>(TypeAliases::VT_V8, None)}
}
#[inline]
pub fn vf64(&self) -> Option<flatbuffers::Vector<'a, f64>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(TypeAliases::VT_VF64, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f64>>>(TypeAliases::VT_VF64, None)}
}
}

View File

@@ -34,39 +34,25 @@ impl core::fmt::Debug for Vec3 {
}
impl flatbuffers::SimpleToVerifyInSlice for Vec3 {}
impl flatbuffers::SafeSliceAccess for Vec3 {}
impl<'a> flatbuffers::Follow<'a> for Vec3 {
type Inner = &'a Vec3;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Vec3>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
type Inner = &'a Vec3;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Vec3 {
type Output = Vec3;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Vec3 {
type Output = Vec3;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -122,121 +108,154 @@ impl<'a> Vec3 {
}
pub fn x(&self) -> f32 {
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
unsafe {
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>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_x(&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 f32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<f32>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
}
}
pub fn y(&self) -> f32 {
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
unsafe {
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>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_y(&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 f32 as *const u8,
&x_le as *const _ as *const u8,
self.0[4..].as_mut_ptr(),
core::mem::size_of::<f32>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
}
}
pub fn z(&self) -> f32 {
let mut mem = core::mem::MaybeUninit::<f32>::uninit();
unsafe {
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>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_z(&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 f32 as *const u8,
&x_le as *const _ as *const u8,
self.0[8..].as_mut_ptr(),
core::mem::size_of::<f32>(),
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
);
}
}
pub fn test1(&self) -> f64 {
let mut mem = core::mem::MaybeUninit::<f64>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<f64 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[16..].as_ptr(),
mem.as_mut_ptr() as *mut u8,
core::mem::size_of::<f64>(),
core::mem::size_of::<<f64 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_test1(&mut self, x: f64) {
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 f64 as *const u8,
&x_le as *const _ as *const u8,
self.0[16..].as_mut_ptr(),
core::mem::size_of::<f64>(),
core::mem::size_of::<<f64 as EndianScalar>::Scalar>(),
);
}
}
pub fn test2(&self) -> Color {
let mut mem = core::mem::MaybeUninit::<Color>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<Color 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[24..].as_ptr(),
mem.as_mut_ptr() as *mut u8,
core::mem::size_of::<Color>(),
core::mem::size_of::<<Color as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_test2(&mut self, x: Color) {
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 Color as *const u8,
&x_le as *const _ as *const u8,
self.0[24..].as_mut_ptr(),
core::mem::size_of::<Color>(),
core::mem::size_of::<<Color as EndianScalar>::Scalar>(),
);
}
}
pub fn test3(&self) -> &Test {
// Safety:
// Created from a valid Table for this object
// Which contains a valid struct in this slot
unsafe { &*(self.0[26..].as_ptr() as *const Test) }
}

View File

@@ -21,8 +21,8 @@ pub struct Monster<'a> {
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
type Inner = Monster<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -33,7 +33,7 @@ impl<'a> Monster<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
Monster { _tab: table }
}
#[allow(unused_mut)]

View File

@@ -21,8 +21,8 @@ pub struct InParentNamespace<'a> {
impl<'a> flatbuffers::Follow<'a> for InParentNamespace<'a> {
type Inner = InParentNamespace<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -33,7 +33,7 @@ impl<'a> InParentNamespace<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
InParentNamespace { _tab: table }
}
#[allow(unused_mut)]

View File

@@ -62,10 +62,8 @@ impl Serialize for FromInclude {
impl<'a> flatbuffers::Follow<'a> for FromInclude {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i64>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
Self(b)
}
}
@@ -73,21 +71,21 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
impl flatbuffers::Push for FromInclude {
type Output = FromInclude;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i64>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i64>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for FromInclude {
type Scalar = i64;
#[inline]
fn to_little_endian(self) -> Self {
let b = i64::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i64 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i64::from_le(self.0);
fn from_little_endian(v: i64) -> Self {
let b = i64::from_le(v);
Self(b)
}
}

View File

@@ -21,8 +21,8 @@ pub struct TableB<'a> {
impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
type Inner = TableB<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -34,7 +34,7 @@ impl<'a> TableB<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableB { _tab: table }
}
#[allow(unused_mut)]
@@ -58,7 +58,10 @@ impl<'a> TableB<'a> {
#[inline]
pub fn a(&self) -> Option<super::super::TableA<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::super::TableA>>(TableB::VT_A, None)}
}
}

View File

@@ -29,39 +29,25 @@ impl core::fmt::Debug for Unused {
}
impl flatbuffers::SimpleToVerifyInSlice for Unused {}
impl flatbuffers::SafeSliceAccess for Unused {}
impl<'a> flatbuffers::Follow<'a> for Unused {
type Inner = &'a Unused;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Unused>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Unused {
type Inner = &'a Unused;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Unused>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Unused {
type Output = Unused;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Unused {
type Output = Unused;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -102,24 +88,30 @@ impl<'a> Unused {
}
pub fn a(&self) -> i32 {
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i32 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::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_a(&mut self, x: i32) {
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 i32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
}
}

View File

@@ -21,8 +21,8 @@ pub struct TableA<'a> {
impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
type Inner = TableA<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -34,7 +34,7 @@ impl<'a> TableA<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableA { _tab: table }
}
#[allow(unused_mut)]
@@ -58,7 +58,10 @@ impl<'a> TableA<'a> {
#[inline]
pub fn b(&self) -> Option<my_game::other_name_space::TableB<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<my_game::other_name_space::TableB>>(TableA::VT_B, None)}
}
}

View File

@@ -59,10 +59,8 @@ impl core::fmt::Debug for ABC {
impl<'a> flatbuffers::Follow<'a> for ABC {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i32>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i32>(buf, loc);
Self(b)
}
}
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for ABC {
impl flatbuffers::Push for ABC {
type Output = ABC;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i32>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i32>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for ABC {
type Scalar = i32;
#[inline]
fn to_little_endian(self) -> Self {
let b = i32::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i32 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i32::from_le(self.0);
fn from_little_endian(v: i32) -> Self {
let b = i32::from_le(v);
Self(b)
}
}

View File

@@ -19,8 +19,8 @@ pub struct MoreDefaults<'a> {
impl<'a> flatbuffers::Follow<'a> for MoreDefaults<'a> {
type Inner = MoreDefaults<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -37,7 +37,7 @@ impl<'a> MoreDefaults<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
MoreDefaults { _tab: table }
}
#[allow(unused_mut)]
@@ -78,7 +78,7 @@ impl<'a> MoreDefaults<'a> {
};
let bools = {
let x = self.bools();
x.to_vec()
x.into_iter().collect()
};
MoreDefaultsT {
ints,
@@ -92,27 +92,45 @@ impl<'a> MoreDefaults<'a> {
#[inline]
pub fn ints(&self) -> flatbuffers::Vector<'a, i32> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i32>>>(MoreDefaults::VT_INTS, Some(Default::default())).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, i32>>>(MoreDefaults::VT_INTS, Some(Default::default())).unwrap()}
}
#[inline]
pub fn floats(&self) -> flatbuffers::Vector<'a, f32> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f32>>>(MoreDefaults::VT_FLOATS, Some(Default::default())).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, f32>>>(MoreDefaults::VT_FLOATS, Some(Default::default())).unwrap()}
}
#[inline]
pub fn empty_string(&self) -> &'a str {
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_EMPTY_STRING, Some(&"")).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_EMPTY_STRING, Some(&"")).unwrap()}
}
#[inline]
pub fn some_string(&self) -> &'a str {
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_SOME_STRING, Some(&"some")).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(MoreDefaults::VT_SOME_STRING, Some(&"some")).unwrap()}
}
#[inline]
pub fn abcs(&self) -> flatbuffers::Vector<'a, ABC> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, ABC>>>(MoreDefaults::VT_ABCS, Some(Default::default())).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, ABC>>>(MoreDefaults::VT_ABCS, Some(Default::default())).unwrap()}
}
#[inline]
pub fn bools(&self) -> &'a [bool] {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(MoreDefaults::VT_BOOLS, Some(Default::default())).map(|v| v.safe_slice()).unwrap()
pub fn bools(&self) -> flatbuffers::Vector<'a, bool> {
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, bool>>>(MoreDefaults::VT_BOOLS, Some(Default::default())).unwrap()}
}
}

View File

@@ -59,10 +59,8 @@ impl core::fmt::Debug for EnumInNestedNS {
impl<'a> flatbuffers::Follow<'a> for EnumInNestedNS {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
Self(b)
}
}
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for EnumInNestedNS {
impl flatbuffers::Push for EnumInNestedNS {
type Output = EnumInNestedNS;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for EnumInNestedNS {
type Scalar = i8;
#[inline]
fn to_little_endian(self) -> Self {
let b = i8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i8::from_le(self.0);
fn from_little_endian(v: i8) -> Self {
let b = i8::from_le(v);
Self(b)
}
}

View File

@@ -28,39 +28,25 @@ impl core::fmt::Debug for StructInNestedNS {
}
impl flatbuffers::SimpleToVerifyInSlice for StructInNestedNS {}
impl flatbuffers::SafeSliceAccess for StructInNestedNS {}
impl<'a> flatbuffers::Follow<'a> for StructInNestedNS {
type Inner = &'a StructInNestedNS;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a StructInNestedNS>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a StructInNestedNS {
type Inner = &'a StructInNestedNS;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<StructInNestedNS>(buf, loc)
}
}
impl<'b> flatbuffers::Push for StructInNestedNS {
type Output = StructInNestedNS;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b StructInNestedNS {
type Output = StructInNestedNS;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const StructInNestedNS as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -92,47 +78,59 @@ impl<'a> StructInNestedNS {
}
pub fn a(&self) -> i32 {
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i32 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::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_a(&mut self, x: i32) {
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 i32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
}
}
pub fn b(&self) -> i32 {
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i32 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::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_b(&mut self, x: i32) {
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 i32 as *const u8,
&x_le as *const _ as *const u8,
self.0[4..].as_mut_ptr(),
core::mem::size_of::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
}
}

View File

@@ -19,8 +19,8 @@ pub struct TableInNestedNS<'a> {
impl<'a> flatbuffers::Follow<'a> for TableInNestedNS<'a> {
type Inner = TableInNestedNS<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> TableInNestedNS<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableInNestedNS { _tab: table }
}
#[allow(unused_mut)]
@@ -54,7 +54,10 @@ impl<'a> TableInNestedNS<'a> {
#[inline]
pub fn foo(&self) -> i32 {
self._tab.get::<i32>(TableInNestedNS::VT_FOO, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(TableInNestedNS::VT_FOO, Some(0)).unwrap()}
}
}

View File

@@ -55,10 +55,8 @@ impl core::fmt::Debug for UnionInNestedNS {
impl<'a> flatbuffers::Follow<'a> for UnionInNestedNS {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
Self(b)
}
}
@@ -66,21 +64,21 @@ impl<'a> flatbuffers::Follow<'a> for UnionInNestedNS {
impl flatbuffers::Push for UnionInNestedNS {
type Output = UnionInNestedNS;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for UnionInNestedNS {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> u8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.0);
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
Self(b)
}
}

View File

@@ -19,8 +19,8 @@ pub struct SecondTableInA<'a> {
impl<'a> flatbuffers::Follow<'a> for SecondTableInA<'a> {
type Inner = SecondTableInA<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> SecondTableInA<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
SecondTableInA { _tab: table }
}
#[allow(unused_mut)]
@@ -56,7 +56,10 @@ impl<'a> SecondTableInA<'a> {
#[inline]
pub fn refer_to_c(&self) -> Option<super::namespace_c::TableInC<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_c::TableInC>>(SecondTableInA::VT_REFER_TO_C, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_c::TableInC>>(SecondTableInA::VT_REFER_TO_C, None)}
}
}

View File

@@ -19,8 +19,8 @@ pub struct TableInFirstNS<'a> {
impl<'a> flatbuffers::Follow<'a> for TableInFirstNS<'a> {
type Inner = TableInFirstNS<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -36,7 +36,7 @@ impl<'a> TableInFirstNS<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableInFirstNS { _tab: table }
}
#[allow(unused_mut)]
@@ -80,29 +80,49 @@ impl<'a> TableInFirstNS<'a> {
#[inline]
pub fn foo_table(&self) -> Option<namespace_b::TableInNestedNS<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<namespace_b::TableInNestedNS>>(TableInFirstNS::VT_FOO_TABLE, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<namespace_b::TableInNestedNS>>(TableInFirstNS::VT_FOO_TABLE, None)}
}
#[inline]
pub fn foo_enum(&self) -> namespace_b::EnumInNestedNS {
self._tab.get::<namespace_b::EnumInNestedNS>(TableInFirstNS::VT_FOO_ENUM, Some(namespace_b::EnumInNestedNS::A)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<namespace_b::EnumInNestedNS>(TableInFirstNS::VT_FOO_ENUM, Some(namespace_b::EnumInNestedNS::A)).unwrap()}
}
#[inline]
pub fn foo_union_type(&self) -> namespace_b::UnionInNestedNS {
self._tab.get::<namespace_b::UnionInNestedNS>(TableInFirstNS::VT_FOO_UNION_TYPE, Some(namespace_b::UnionInNestedNS::NONE)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<namespace_b::UnionInNestedNS>(TableInFirstNS::VT_FOO_UNION_TYPE, Some(namespace_b::UnionInNestedNS::NONE)).unwrap()}
}
#[inline]
pub fn foo_union(&self) -> Option<flatbuffers::Table<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(TableInFirstNS::VT_FOO_UNION, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(TableInFirstNS::VT_FOO_UNION, None)}
}
#[inline]
pub fn foo_struct(&self) -> Option<&'a namespace_b::StructInNestedNS> {
self._tab.get::<namespace_b::StructInNestedNS>(TableInFirstNS::VT_FOO_STRUCT, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<namespace_b::StructInNestedNS>(TableInFirstNS::VT_FOO_STRUCT, None)}
}
#[inline]
#[allow(non_snake_case)]
pub fn foo_union_as_table_in_nested_ns(&self) -> Option<namespace_b::TableInNestedNS<'a>> {
if self.foo_union_type() == namespace_b::UnionInNestedNS::TableInNestedNS {
self.foo_union().map(namespace_b::TableInNestedNS::init_from_table)
self.foo_union().map(|t| {
// Safety:
// Created from a valid Table for this object
// Which contains a valid union in this slot
unsafe { namespace_b::TableInNestedNS::init_from_table(t) }
})
} else {
None
}

View File

@@ -19,8 +19,8 @@ pub struct TableInC<'a> {
impl<'a> flatbuffers::Follow<'a> for TableInC<'a> {
type Inner = TableInC<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -33,7 +33,7 @@ impl<'a> TableInC<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
TableInC { _tab: table }
}
#[allow(unused_mut)]
@@ -62,11 +62,17 @@ impl<'a> TableInC<'a> {
#[inline]
pub fn refer_to_a1(&self) -> Option<super::namespace_a::TableInFirstNS<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::TableInFirstNS>>(TableInC::VT_REFER_TO_A1, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::TableInFirstNS>>(TableInC::VT_REFER_TO_A1, None)}
}
#[inline]
pub fn refer_to_a2(&self) -> Option<super::namespace_a::SecondTableInA<'a>> {
self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::SecondTableInA>>(TableInC::VT_REFER_TO_A2, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::SecondTableInA>>(TableInC::VT_REFER_TO_A2, None)}
}
}

View File

@@ -59,10 +59,8 @@ impl core::fmt::Debug for OptionalByte {
impl<'a> flatbuffers::Follow<'a> for OptionalByte {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
Self(b)
}
}
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for OptionalByte {
impl flatbuffers::Push for OptionalByte {
type Output = OptionalByte;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for OptionalByte {
type Scalar = i8;
#[inline]
fn to_little_endian(self) -> Self {
let b = i8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i8::from_le(self.0);
fn from_little_endian(v: i8) -> Self {
let b = i8::from_le(v);
Self(b)
}
}

View File

@@ -19,8 +19,8 @@ pub struct ScalarStuff<'a> {
impl<'a> flatbuffers::Follow<'a> for ScalarStuff<'a> {
type Inner = ScalarStuff<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -67,7 +67,7 @@ impl<'a> ScalarStuff<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
ScalarStuff { _tab: table }
}
#[allow(unused_mut)]
@@ -194,147 +194,255 @@ impl<'a> ScalarStuff<'a> {
#[inline]
pub fn just_i8(&self) -> i8 {
self._tab.get::<i8>(ScalarStuff::VT_JUST_I8, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i8>(ScalarStuff::VT_JUST_I8, Some(0)).unwrap()}
}
#[inline]
pub fn maybe_i8(&self) -> Option<i8> {
self._tab.get::<i8>(ScalarStuff::VT_MAYBE_I8, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i8>(ScalarStuff::VT_MAYBE_I8, None)}
}
#[inline]
pub fn default_i8(&self) -> i8 {
self._tab.get::<i8>(ScalarStuff::VT_DEFAULT_I8, Some(42)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i8>(ScalarStuff::VT_DEFAULT_I8, Some(42)).unwrap()}
}
#[inline]
pub fn just_u8(&self) -> u8 {
self._tab.get::<u8>(ScalarStuff::VT_JUST_U8, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u8>(ScalarStuff::VT_JUST_U8, Some(0)).unwrap()}
}
#[inline]
pub fn maybe_u8(&self) -> Option<u8> {
self._tab.get::<u8>(ScalarStuff::VT_MAYBE_U8, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u8>(ScalarStuff::VT_MAYBE_U8, None)}
}
#[inline]
pub fn default_u8(&self) -> u8 {
self._tab.get::<u8>(ScalarStuff::VT_DEFAULT_U8, Some(42)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u8>(ScalarStuff::VT_DEFAULT_U8, Some(42)).unwrap()}
}
#[inline]
pub fn just_i16(&self) -> i16 {
self._tab.get::<i16>(ScalarStuff::VT_JUST_I16, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i16>(ScalarStuff::VT_JUST_I16, Some(0)).unwrap()}
}
#[inline]
pub fn maybe_i16(&self) -> Option<i16> {
self._tab.get::<i16>(ScalarStuff::VT_MAYBE_I16, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i16>(ScalarStuff::VT_MAYBE_I16, None)}
}
#[inline]
pub fn default_i16(&self) -> i16 {
self._tab.get::<i16>(ScalarStuff::VT_DEFAULT_I16, Some(42)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i16>(ScalarStuff::VT_DEFAULT_I16, Some(42)).unwrap()}
}
#[inline]
pub fn just_u16(&self) -> u16 {
self._tab.get::<u16>(ScalarStuff::VT_JUST_U16, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u16>(ScalarStuff::VT_JUST_U16, Some(0)).unwrap()}
}
#[inline]
pub fn maybe_u16(&self) -> Option<u16> {
self._tab.get::<u16>(ScalarStuff::VT_MAYBE_U16, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u16>(ScalarStuff::VT_MAYBE_U16, None)}
}
#[inline]
pub fn default_u16(&self) -> u16 {
self._tab.get::<u16>(ScalarStuff::VT_DEFAULT_U16, Some(42)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u16>(ScalarStuff::VT_DEFAULT_U16, Some(42)).unwrap()}
}
#[inline]
pub fn just_i32(&self) -> i32 {
self._tab.get::<i32>(ScalarStuff::VT_JUST_I32, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(ScalarStuff::VT_JUST_I32, Some(0)).unwrap()}
}
#[inline]
pub fn maybe_i32(&self) -> Option<i32> {
self._tab.get::<i32>(ScalarStuff::VT_MAYBE_I32, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(ScalarStuff::VT_MAYBE_I32, None)}
}
#[inline]
pub fn default_i32(&self) -> i32 {
self._tab.get::<i32>(ScalarStuff::VT_DEFAULT_I32, Some(42)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(ScalarStuff::VT_DEFAULT_I32, Some(42)).unwrap()}
}
#[inline]
pub fn just_u32(&self) -> u32 {
self._tab.get::<u32>(ScalarStuff::VT_JUST_U32, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u32>(ScalarStuff::VT_JUST_U32, Some(0)).unwrap()}
}
#[inline]
pub fn maybe_u32(&self) -> Option<u32> {
self._tab.get::<u32>(ScalarStuff::VT_MAYBE_U32, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u32>(ScalarStuff::VT_MAYBE_U32, None)}
}
#[inline]
pub fn default_u32(&self) -> u32 {
self._tab.get::<u32>(ScalarStuff::VT_DEFAULT_U32, Some(42)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u32>(ScalarStuff::VT_DEFAULT_U32, Some(42)).unwrap()}
}
#[inline]
pub fn just_i64(&self) -> i64 {
self._tab.get::<i64>(ScalarStuff::VT_JUST_I64, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(ScalarStuff::VT_JUST_I64, Some(0)).unwrap()}
}
#[inline]
pub fn maybe_i64(&self) -> Option<i64> {
self._tab.get::<i64>(ScalarStuff::VT_MAYBE_I64, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(ScalarStuff::VT_MAYBE_I64, None)}
}
#[inline]
pub fn default_i64(&self) -> i64 {
self._tab.get::<i64>(ScalarStuff::VT_DEFAULT_I64, Some(42)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i64>(ScalarStuff::VT_DEFAULT_I64, Some(42)).unwrap()}
}
#[inline]
pub fn just_u64(&self) -> u64 {
self._tab.get::<u64>(ScalarStuff::VT_JUST_U64, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(ScalarStuff::VT_JUST_U64, Some(0)).unwrap()}
}
#[inline]
pub fn maybe_u64(&self) -> Option<u64> {
self._tab.get::<u64>(ScalarStuff::VT_MAYBE_U64, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(ScalarStuff::VT_MAYBE_U64, None)}
}
#[inline]
pub fn default_u64(&self) -> u64 {
self._tab.get::<u64>(ScalarStuff::VT_DEFAULT_U64, Some(42)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<u64>(ScalarStuff::VT_DEFAULT_U64, Some(42)).unwrap()}
}
#[inline]
pub fn just_f32(&self) -> f32 {
self._tab.get::<f32>(ScalarStuff::VT_JUST_F32, Some(0.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(ScalarStuff::VT_JUST_F32, Some(0.0)).unwrap()}
}
#[inline]
pub fn maybe_f32(&self) -> Option<f32> {
self._tab.get::<f32>(ScalarStuff::VT_MAYBE_F32, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(ScalarStuff::VT_MAYBE_F32, None)}
}
#[inline]
pub fn default_f32(&self) -> f32 {
self._tab.get::<f32>(ScalarStuff::VT_DEFAULT_F32, Some(42.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f32>(ScalarStuff::VT_DEFAULT_F32, Some(42.0)).unwrap()}
}
#[inline]
pub fn just_f64(&self) -> f64 {
self._tab.get::<f64>(ScalarStuff::VT_JUST_F64, Some(0.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f64>(ScalarStuff::VT_JUST_F64, Some(0.0)).unwrap()}
}
#[inline]
pub fn maybe_f64(&self) -> Option<f64> {
self._tab.get::<f64>(ScalarStuff::VT_MAYBE_F64, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f64>(ScalarStuff::VT_MAYBE_F64, None)}
}
#[inline]
pub fn default_f64(&self) -> f64 {
self._tab.get::<f64>(ScalarStuff::VT_DEFAULT_F64, Some(42.0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<f64>(ScalarStuff::VT_DEFAULT_F64, Some(42.0)).unwrap()}
}
#[inline]
pub fn just_bool(&self) -> bool {
self._tab.get::<bool>(ScalarStuff::VT_JUST_BOOL, Some(false)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<bool>(ScalarStuff::VT_JUST_BOOL, Some(false)).unwrap()}
}
#[inline]
pub fn maybe_bool(&self) -> Option<bool> {
self._tab.get::<bool>(ScalarStuff::VT_MAYBE_BOOL, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<bool>(ScalarStuff::VT_MAYBE_BOOL, None)}
}
#[inline]
pub fn default_bool(&self) -> bool {
self._tab.get::<bool>(ScalarStuff::VT_DEFAULT_BOOL, Some(true)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<bool>(ScalarStuff::VT_DEFAULT_BOOL, Some(true)).unwrap()}
}
#[inline]
pub fn just_enum(&self) -> OptionalByte {
self._tab.get::<OptionalByte>(ScalarStuff::VT_JUST_ENUM, Some(OptionalByte::None)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<OptionalByte>(ScalarStuff::VT_JUST_ENUM, Some(OptionalByte::None)).unwrap()}
}
#[inline]
pub fn maybe_enum(&self) -> Option<OptionalByte> {
self._tab.get::<OptionalByte>(ScalarStuff::VT_MAYBE_ENUM, None)
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<OptionalByte>(ScalarStuff::VT_MAYBE_ENUM, None)}
}
#[inline]
pub fn default_enum(&self) -> OptionalByte {
self._tab.get::<OptionalByte>(ScalarStuff::VT_DEFAULT_ENUM, Some(OptionalByte::One)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<OptionalByte>(ScalarStuff::VT_DEFAULT_ENUM, Some(OptionalByte::One)).unwrap()}
}
}
@@ -836,18 +944,6 @@ impl ScalarStuffT {
})
}
}
#[inline]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_root_as_scalar_stuff<'a>(buf: &'a [u8]) -> ScalarStuff<'a> {
unsafe { flatbuffers::root_unchecked::<ScalarStuff<'a>>(buf) }
}
#[inline]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_size_prefixed_root_as_scalar_stuff<'a>(buf: &'a [u8]) -> ScalarStuff<'a> {
unsafe { flatbuffers::size_prefixed_root_unchecked::<ScalarStuff<'a>>(buf) }
}
#[inline]
/// Verifies that a buffer of bytes contains a `ScalarStuff`
/// and returns it.

View File

@@ -55,10 +55,8 @@ impl core::fmt::Debug for AB {
impl<'a> flatbuffers::Follow<'a> for AB {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<i8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
Self(b)
}
}
@@ -66,21 +64,21 @@ impl<'a> flatbuffers::Follow<'a> for AB {
impl flatbuffers::Push for AB {
type Output = AB;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for AB {
type Scalar = i8;
#[inline]
fn to_little_endian(self) -> Self {
let b = i8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> i8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = i8::from_le(self.0);
fn from_little_endian(v: i8) -> Self {
let b = i8::from_le(v);
Self(b)
}
}

View File

@@ -19,8 +19,8 @@ pub(crate) struct Annotations<'a> {
impl<'a> flatbuffers::Follow<'a> for Annotations<'a> {
type Inner = Annotations<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> Annotations<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
Annotations { _tab: table }
}
#[allow(unused_mut)]
@@ -54,7 +54,10 @@ impl<'a> Annotations<'a> {
#[inline]
pub fn value(&self) -> i32 {
self._tab.get::<i32>(Annotations::VT_VALUE, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(Annotations::VT_VALUE, Some(0)).unwrap()}
}
}

View File

@@ -59,10 +59,8 @@ impl core::fmt::Debug for Any {
impl<'a> flatbuffers::Follow<'a> for Any {
type Inner = Self;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe {
flatbuffers::read_scalar_at::<u8>(buf, loc)
};
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
Self(b)
}
}
@@ -70,21 +68,21 @@ impl<'a> flatbuffers::Follow<'a> for Any {
impl flatbuffers::Push for Any {
type Output = Any;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.0);
}
}
impl flatbuffers::EndianScalar for Any {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> Self {
let b = u8::to_le(self.0);
Self(b)
fn to_little_endian(self) -> u8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(self) -> Self {
let b = u8::from_le(self.0);
fn from_little_endian(v: u8) -> Self {
let b = u8::from_le(v);
Self(b)
}
}

View File

@@ -19,8 +19,8 @@ pub(crate) struct Game<'a> {
impl<'a> flatbuffers::Follow<'a> for Game<'a> {
type Inner = Game<'a>;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table { buf, loc } }
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
}
}
@@ -32,7 +32,7 @@ impl<'a> Game<'a> {
}
#[inline]
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
Game { _tab: table }
}
#[allow(unused_mut)]
@@ -54,7 +54,10 @@ impl<'a> Game<'a> {
#[inline]
pub fn value(&self) -> i32 {
self._tab.get::<i32>(Game::VT_VALUE, Some(0)).unwrap()
// Safety:
// Created from valid Table for this object
// which contains a valid value in this slot
unsafe { self._tab.get::<i32>(Game::VT_VALUE, Some(0)).unwrap()}
}
}

View File

@@ -27,39 +27,25 @@ impl core::fmt::Debug for Object {
}
impl flatbuffers::SimpleToVerifyInSlice for Object {}
impl flatbuffers::SafeSliceAccess for Object {}
impl<'a> flatbuffers::Follow<'a> for Object {
type Inner = &'a Object;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Object>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Object {
type Inner = &'a Object;
#[inline]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Object>(buf, loc)
}
}
impl<'b> flatbuffers::Push for Object {
type Output = Object;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(self as *const Object as *const u8, Self::size())
};
dst.copy_from_slice(src);
}
}
impl<'b> flatbuffers::Push for &'b Object {
type Output = Object;
#[inline]
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const Object as *const u8, Self::size())
};
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());
dst.copy_from_slice(src);
}
}
@@ -89,24 +75,30 @@ impl<'a> Object {
}
pub fn value(&self) -> i32 {
let mut mem = core::mem::MaybeUninit::<i32>::uninit();
unsafe {
let mut mem = core::mem::MaybeUninit::<<i32 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::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
mem.assume_init()
}.from_little_endian()
})
}
pub fn set_value(&mut self, x: i32) {
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 i32 as *const u8,
&x_le as *const _ as *const u8,
self.0[0..].as_mut_ptr(),
core::mem::size_of::<i32>(),
core::mem::size_of::<<i32 as EndianScalar>::Scalar>(),
);
}
}

View File

@@ -36,8 +36,8 @@ fn create_serialized_example_with_generated_code(builder: &mut flatbuffers::Flat
)
.as_union_value(),
),
inventory: Some(builder.create_vector_direct(&[0u8, 1, 2, 3, 4][..])),
test4: Some(builder.create_vector_direct(&[
inventory: Some(builder.create_vector(&[0u8, 1, 2, 3, 4])),
test4: Some(builder.create_vector(&[
my_game::example::Test::new(10, 20),
my_game::example::Test::new(30, 40),
])),

View File

@@ -86,8 +86,8 @@ fn create_serialized_example_with_generated_code(
let mon = {
let name = builder.create_string("MyMonster");
let fred_name = builder.create_string("Fred");
let inventory = builder.create_vector_direct(&[0u8, 1, 2, 3, 4]);
let test4 = builder.create_vector_direct(&[
let inventory = builder.create_vector(&[0u8, 1, 2, 3, 4]);
let test4 = builder.create_vector(&[
my_game::example::Test::new(10, 20),
my_game::example::Test::new(30, 40),
]);
@@ -156,7 +156,7 @@ fn traverse_serialized_example_with_generated_code(bytes: &[u8]) {
blackbox(pos_test3.b());
blackbox(m.test_type());
let table2 = m.test().unwrap();
let monster2 = my_game::example::Monster::init_from_table(table2);
let monster2 = unsafe { my_game::example::Monster::init_from_table(table2) };
blackbox(monster2.name());
blackbox(m.inventory());
blackbox(m.test4());
@@ -228,7 +228,7 @@ fn create_byte_vector_100_optimal(bench: &mut Bencher) {
let mut i = 0;
bench.iter(|| {
builder.create_vector_direct(v);
builder.create_vector(v);
i += 1;
if i == 10000 {
builder.reset();

View File

@@ -12,6 +12,7 @@ impl TrackingAllocator {
unsafe { N_ALLOCS }
}
}
unsafe impl GlobalAlloc for TrackingAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
N_ALLOCS += 1;
@@ -28,6 +29,7 @@ static A: TrackingAllocator = TrackingAllocator;
// import the flatbuffers generated code:
extern crate flatbuffers;
#[allow(dead_code, unused_imports)]
#[path = "../../include_test1/mod.rs"]
pub mod include_test1_generated;
@@ -39,20 +41,22 @@ pub mod include_test2_generated;
#[allow(dead_code, unused_imports, clippy::approx_constant)]
#[path = "../../monster_test/mod.rs"]
mod monster_test_generated;
pub use monster_test_generated::my_game;
// verbatim from the test suite:
fn create_serialized_example_with_generated_code(builder: &mut flatbuffers::FlatBufferBuilder) {
let mon = {
let _ = builder.create_vector_of_strings(&[
"these",
"unused",
"strings",
"check",
"the",
"create_vector_of_strings",
"function",
]);
let strings = [
builder.create_string("these"),
builder.create_string("unused"),
builder.create_string("strings"),
builder.create_string("check"),
builder.create_string("the"),
builder.create_string("create_vector_of_strings"),
builder.create_string("function")
];
let _ = builder.create_vector(&strings);
let s0 = builder.create_string("test1");
let s1 = builder.create_string("test2");
@@ -83,10 +87,10 @@ fn create_serialized_example_with_generated_code(builder: &mut flatbuffers::Flat
..Default::default()
},
)
.as_union_value(),
.as_union_value(),
),
inventory: Some(builder.create_vector_direct(&[0u8, 1, 2, 3, 4][..])),
test4: Some(builder.create_vector_direct(&[
inventory: Some(builder.create_vector(&[0u8, 1, 2, 3, 4])),
test4: Some(builder.create_vector(&[
my_game::example::Test::new(10, 20),
my_game::example::Test::new(30, 40),
])),
@@ -151,7 +155,7 @@ fn main() {
assert_eq!(pos_test3.b(), 6i8);
assert_eq!(m.test_type(), my_game::example::Any::Monster);
let table2 = m.test().unwrap();
let m2 = my_game::example::Monster::init_from_table(table2);
let m2 = unsafe { my_game::example::Monster::init_from_table(table2) };
assert_eq!(m2.name(), "Fred");
@@ -162,10 +166,10 @@ fn main() {
let test4 = m.test4().unwrap();
assert_eq!(test4.len(), 2);
assert_eq!(
i32::from(test4[0].a())
+ i32::from(test4[1].a())
+ i32::from(test4[0].b())
+ i32::from(test4[1].b()),
i32::from(test4.get(0).a())
+ i32::from(test4.get(1).a())
+ i32::from(test4.get(0).b())
+ i32::from(test4.get(1).b()),
100
);

View File

@@ -6,14 +6,18 @@ extern crate std;
extern crate alloc;
extern crate array_init;
#[allow(dead_code, unused_imports)]
#[path = "../../arrays_test/mod.rs"]
mod arrays_test_generated;
use alloc::format;
use core::fmt::Debug;
use crate::arrays_test_generated::my_game::example::*;
extern crate quickcheck;
use array_init::array_init;
use core::mem::size_of;
use quickcheck::{Arbitrary, Gen};
@@ -60,6 +64,7 @@ fn serialized_example_is_accessible_and_correct(
} else {
array_table_buffer_has_identifier(bytes)
};
assert_eq!(correct, true);
}
@@ -175,7 +180,7 @@ fn object_api_defaults() {
a: [0, 0],
b: TestEnum::default(),
c: [TestEnum::default(), TestEnum::default()],
d: [0, 0]
d: [0, 0],
}
);
@@ -187,7 +192,7 @@ fn object_api_defaults() {
c: 0,
d: [NestedStructT::default(), NestedStructT::default()],
e: 0,
f: [0, 0]
f: [0, 0],
}
);
}
@@ -213,14 +218,14 @@ fn generated_code_debug_prints_correctly() {
#[should_panic]
fn assert_on_too_small_array_buf() {
let a = [0u8; 19];
flatbuffers::Array::<i32, 5>::new(&a);
unsafe { flatbuffers::Array::<i32, 5>::new(&a) };
}
#[test]
#[should_panic]
fn assert_on_too_big_array_buf() {
let a = [0u8; 21];
flatbuffers::Array::<i32, 5>::new(&a);
unsafe { flatbuffers::Array::<i32, 5>::new(&a) };
}
#[test]
@@ -251,10 +256,10 @@ impl<T: Arbitrary + Debug + PartialEq, const N: usize> Arbitrary for FakeArray<T
let generated_scalar = T::arbitrary(g);
// Verify that generated scalar is not Nan, which is not equals to itself,
// therefore we can't use it to validate input == output
if generated_scalar == generated_scalar { return generated_scalar }
if generated_scalar == generated_scalar { return generated_scalar; }
}
});
FakeArray{0: x}
FakeArray { 0: x }
}
}
@@ -263,6 +268,7 @@ mod array_fuzz {
#[cfg(not(miri))] // slow.
extern crate quickcheck;
extern crate flatbuffers;
use self::flatbuffers::{Follow, Push};
use super::*;
@@ -275,8 +281,10 @@ mod array_fuzz {
($test_name:ident, $fn_name:ident, $ty:ident) => (
fn $fn_name(xs: FakeArray<$ty, ARRAY_SIZE>) {
let mut test_buf = [0 as u8; 1024];
flatbuffers::emplace_scalar_array(&mut test_buf, 0, &xs.0);
let arr: flatbuffers::Array<$ty, ARRAY_SIZE> = flatbuffers::Array::follow(&test_buf, 0);
let arr: flatbuffers::Array<$ty, ARRAY_SIZE> = unsafe {
flatbuffers::emplace_scalar_array(&mut test_buf, 0, &xs.0);
flatbuffers::Array::follow(&test_buf, 0)
};
let got: [$ty; ARRAY_SIZE] = arr.into();
assert_eq!(got, xs.0);
}
@@ -308,7 +316,7 @@ mod array_fuzz {
fn arbitrary<G: Gen>(g: &mut G) -> NestedStructWrapper {
let mut x = NestedStruct::default();
x.0 = FakeArray::<u8, NESTED_STRUCT_SIZE>::arbitrary(g).0;
NestedStructWrapper{0: x}
NestedStructWrapper { 0: x }
}
}
@@ -317,16 +325,16 @@ mod array_fuzz {
let native_struct_array: [&NestedStruct; ARRAY_SIZE] = array_init::from_iter(xs.0.iter().map(|x| &x.0)).unwrap();
for i in 0..ARRAY_SIZE {
let offset = i * NESTED_STRUCT_SIZE;
native_struct_array[i].push(&mut test_buf[offset..offset + NESTED_STRUCT_SIZE], &[]);
unsafe { native_struct_array[i].push(&mut test_buf[offset..offset + NESTED_STRUCT_SIZE], 0) };
}
let arr: flatbuffers::Array<NestedStruct, ARRAY_SIZE> = flatbuffers::Array::follow(&test_buf, 0);
let arr: flatbuffers::Array<NestedStruct, ARRAY_SIZE> = unsafe { flatbuffers::Array::follow(&test_buf, 0) };
let got: [&NestedStruct; ARRAY_SIZE] = arr.into();
assert_eq!(got, native_struct_array);
}
#[test]
#[cfg(not(miri))] // slow.
fn test_struct() {
fn test_struct() {
quickcheck::QuickCheck::new().max_tests(MAX_TESTS).quickcheck(prop_struct as fn(FakeArray<NestedStructWrapper, ARRAY_SIZE>));
}
}

View File

@@ -229,8 +229,8 @@ fn create_serialized_example_with_generated_code(builder: &mut flatbuffers::Flat
name: Some(fred_name),
..Default::default()
}).as_union_value()),
inventory: Some(builder.create_vector_direct(&[0u8, 1, 2, 3, 4][..])),
test4: Some(builder.create_vector_direct(&[my_game::example::Test::new(10, 20),
inventory: Some(builder.create_vector(&[0u8, 1, 2, 3, 4])),
test4: Some(builder.create_vector(&[my_game::example::Test::new(10, 20),
my_game::example::Test::new(30, 40)])),
testarrayofstring: Some(builder.create_vector(&[s0, s1])),
..Default::default()
@@ -254,7 +254,11 @@ fn create_serialized_example_with_library_code(builder: &mut flatbuffers::FlatBu
my_game::example::Test::new(30, 40)][..]);
let name = builder.create_string("MyMonster");
let testarrayofstring = builder.create_vector_of_strings(&["test1", "test2"][..]);
let test1 = builder.create_string("test1");
let test2 = builder.create_string("test2");
let testarrayofstring = builder.create_vector(&[test1, test2]);
// begin building
@@ -306,7 +310,7 @@ fn serialized_example_is_accessible_and_correct(bytes: &[u8], identifier_require
check_eq!(m.test_type(), my_game::example::Any::Monster)?;
check_is_some!(m.test())?;
let table2 = m.test().unwrap();
let monster2 = my_game::example::Monster::init_from_table(table2);
let monster2 = unsafe { my_game::example::Monster::init_from_table(table2) };
check_eq!(monster2.name(), "Fred")?;
@@ -319,8 +323,8 @@ fn serialized_example_is_accessible_and_correct(bytes: &[u8], identifier_require
check_is_some!(m.test4())?;
let test4 = m.test4().unwrap();
check_eq!(test4.len(), 2)?;
check_eq!(test4[0].a() as i32 + test4[0].b() as i32 +
test4[1].a() as i32 + test4[1].b() as i32, 100)?;
check_eq!(test4.get(0).a() as i32 + test4.get(0).b() as i32 +
test4.get(1).a() as i32 + test4.get(1).b() as i32, 100)?;
check_is_some!(m.testarrayofstring())?;
let testarrayofstring = m.testarrayofstring().unwrap();
@@ -572,16 +576,16 @@ mod lifetime_correctness {
// make sure values retrieved from the 'static buffer are themselves 'static
let monster: my_game::example::Monster<'static> = my_game::example::root_as_monster(slice).unwrap();
// this line should compile:
let name: Option<&'static str> = monster._tab.get::<flatbuffers::ForwardsUOffset<&str>>(my_game::example::Monster::VT_NAME, None);
let name: Option<&'static str> = unsafe { monster._tab.get::<flatbuffers::ForwardsUOffset<&str>>(my_game::example::Monster::VT_NAME, None) };
assert_eq!(name, Some("MyMonster"));
}
#[test]
fn table_get_field_from_static_buffer_2() {
static DATA: [u8; 4] = [0, 0, 0, 0]; // some binary data
let table: flatbuffers::Table<'static> = flatbuffers::Table::new(&DATA, 0);
let table: flatbuffers::Table<'static> = unsafe { flatbuffers::Table::new(&DATA, 0) };
// this line should compile:
table.get::<&'static str>(0, None);
unsafe { table.get::<&'static str>(0, None) };
}
#[test]
@@ -696,8 +700,8 @@ mod roundtrip_generated_code {
let mon = my_game::example::root_as_monster(b.finished_data()).unwrap();
assert_eq!(mon.name(), "bar");
assert_eq!(mon.test_type(), my_game::example::Any::Monster);
assert_eq!(my_game::example::Monster::init_from_table(mon.test().unwrap()).name(),
"foo");
let name = unsafe { my_game::example::Monster::init_from_table(mon.test().unwrap()).name() };
assert_eq!(name, "foo");
assert_eq!(mon.test_as_monster().unwrap().name(), "foo");
assert_eq!(mon.test_as_test_simple_table_with_enum(), None);
assert_eq!(mon.test_as_my_game_example_2_monster(), None);
@@ -799,9 +803,9 @@ mod roundtrip_generated_code {
let m = my_game::example::root_as_monster(b1.finished_data()).unwrap();
assert!(m.testnestedflatbuffer().is_some());
assert_eq!(m.testnestedflatbuffer().unwrap(), b0.finished_data());
assert_eq!(m.testnestedflatbuffer().unwrap().bytes(), b0.finished_data());
let m2_a = my_game::example::root_as_monster(m.testnestedflatbuffer().unwrap()).unwrap();
let m2_a = my_game::example::root_as_monster(m.testnestedflatbuffer().unwrap().bytes()).unwrap();
assert_eq!(m2_a.hp(), 123);
assert_eq!(m2_a.name(), "foobar");
@@ -821,7 +825,8 @@ mod roundtrip_generated_code {
#[test]
fn vector_of_string_store_helper_build() {
let mut b = flatbuffers::FlatBufferBuilder::new();
let v = b.create_vector_of_strings(&["foobar", "baz"]);
let strings = &[b.create_string("foobar"), b.create_string("baz")];
let v = b.create_vector(strings);
let name = b.create_string("foo");
let m = build_mon(&mut b, &my_game::example::MonsterArgs{
name: Some(name),
@@ -874,8 +879,9 @@ mod roundtrip_generated_code {
let name = b.create_string("foo");
let m = build_mon(&mut b, &my_game::example::MonsterArgs{
name: Some(name),
inventory: Some(v), ..Default::default()});
assert_eq!(m.inventory().unwrap(), &[123, 234][..]);
inventory: Some(v), ..Default::default()
});
assert_eq!(m.inventory().unwrap().bytes(), &[123, 234]);
}
#[test]
fn vector_of_bool_store() {
@@ -885,14 +891,13 @@ mod roundtrip_generated_code {
let m = build_mon(&mut b, &my_game::example::MonsterArgs{
name: Some(name),
testarrayofbools: Some(v), ..Default::default()});
assert_eq!(m.testarrayofbools().unwrap(), &[false, true, false, true][..]);
let rust_vec_inst = m.testarrayofbools().unwrap();
let rust_vec_iter_collect = rust_vec_inst.iter().collect::<Vec<_>>();
assert_eq!(rust_vec_iter_collect, &[&false, &true, &false, &true][..]);
assert_eq!(&rust_vec_iter_collect, &[false, true, false, true]);
let rust_vec_iter_rev_collect = rust_vec_inst.iter().rev().collect::<Vec<_>>();
assert_eq!(rust_vec_iter_rev_collect, &[&true, &false, &true, &false][..]);
assert_eq!(&rust_vec_iter_rev_collect, &[true, false, true, false]);
}
#[test]
fn vector_of_f64_store() {
@@ -922,7 +927,6 @@ mod roundtrip_generated_code {
let m = build_mon(&mut b, &my_game::example::MonsterArgs{
name: Some(name),
test4: Some(v), ..Default::default()});
assert_eq!(m.test4().unwrap(), &[my_game::example::Test::new(127, -128), my_game::example::Test::new(3, 123)][..]);
let rust_vec_inst = m.test4().unwrap();
let rust_vec_iter_collect = rust_vec_inst.iter().collect::<Vec<_>>();
@@ -941,7 +945,8 @@ mod roundtrip_generated_code {
let m = build_mon(&mut b, &my_game::example::MonsterArgs{
name: Some(name),
test4: Some(v), ..Default::default()});
assert_eq!(m.test4().unwrap(), &[my_game::example::Test::new(127, -128), my_game::example::Test::new(3, 123), my_game::example::Test::new(100, 101)][..]);
let vals: Vec<_> = m.test4().unwrap().iter().collect::<Vec<_>>();
assert_eq!(vals, vec![&my_game::example::Test::new(127, -128), &my_game::example::Test::new(3, 123), &my_game::example::Test::new(100, 101)]);
}
#[test]
fn vector_of_enums_store() {
@@ -1088,56 +1093,6 @@ mod generated_code_alignment_and_padding {
}
}
#[cfg(test)]
mod roundtrip_byteswap {
#[cfg(not(miri))] // slow.
extern crate quickcheck;
extern crate flatbuffers;
const N: u64 = 10000;
fn palindrome_32(x: f32) -> bool {
x == f32::from_bits(x.to_bits().swap_bytes())
}
fn palindrome_64(x: f64) -> bool {
x == f64::from_bits(x.to_bits().swap_bytes())
}
fn prop_f32(x: f32) {
use flatbuffers::byte_swap_f32;
let there = byte_swap_f32(x);
let back_again = byte_swap_f32(there);
if !palindrome_32(x) {
assert!(x != there);
}
assert_eq!(x, back_again);
}
fn prop_f64(x: f64) {
use flatbuffers::byte_swap_f64;
let there = byte_swap_f64(x);
let back_again = byte_swap_f64(there);
if !palindrome_64(x) {
assert!(x != there);
}
assert_eq!(x, back_again);
}
// TODO(rw): Replace the implementations with the new stdlib endian-conversion functions.
// TODO(rw): Re-enable these tests (currently, rare CI failures occur that seem spurious).
// #[test]
// fn fuzz_f32() { quickcheck::QuickCheck::new().max_tests(N).quickcheck(prop_f32 as fn(f32)); }
// #[test]
// fn fuzz_f64() { quickcheck::QuickCheck::new().max_tests(N).quickcheck(prop_f64 as fn(f64)); }
}
#[cfg(not(miri))]
quickcheck! {
fn struct_of_structs(
@@ -1204,7 +1159,7 @@ mod roundtrip_vectors {
let buf = b.finished_data();
let got = <flatbuffers::ForwardsUOffset<flatbuffers::Vector<T>>>::follow(&buf[..], 0);
let got = unsafe { <flatbuffers::ForwardsUOffset<flatbuffers::Vector<T>>>::follow(&buf[..], 0) };
let mut result_vec: Vec<T> = Vec::with_capacity(got.len());
for i in 0..got.len() {
result_vec.push(got.get(i));
@@ -1252,54 +1207,6 @@ mod roundtrip_vectors {
fn fuzz_f64() { quickcheck::QuickCheck::new().max_tests(N).quickcheck(prop::<f64> as fn(Vec<_>)); }
}
#[cfg(test)]
mod create_vector_direct {
#[cfg(not(miri))] // slow.
extern crate quickcheck;
extern crate flatbuffers;
const N: u64 = 20;
// This uses a macro because lifetimes for the trait-bounded function get too
// complicated.
macro_rules! impl_prop {
($test_name:ident, $fn_name:ident, $ty:ident) => (
fn $fn_name(xs: alloc::vec::Vec<$ty>) {
use flatbuffers::Follow;
let mut b = flatbuffers::FlatBufferBuilder::new();
b.create_vector_direct(&xs[..]);
let buf = b.unfinished_data();
let got = <flatbuffers::Vector<$ty>>::follow(&buf[..], 0).safe_slice();
assert_eq!(got, &xs[..]);
}
#[test]
fn $test_name() { quickcheck::QuickCheck::new().max_tests(N).quickcheck($fn_name as fn(alloc::vec::Vec<_>)); }
)
}
impl_prop!(test_bool, prop_bool, bool);
impl_prop!(test_u8, prop_u8, u8);
impl_prop!(test_i8, prop_i8, i8);
#[cfg(test)]
#[cfg(target_endian = "little")]
mod host_is_le {
const N: u64 = 20;
use super::flatbuffers;
use super::quickcheck;
impl_prop!(test_u16, prop_u16, u16);
impl_prop!(test_u32, prop_u32, u32);
impl_prop!(test_u64, prop_u64, u64);
impl_prop!(test_i16, prop_i16, i16);
impl_prop!(test_i32, prop_i32, i32);
impl_prop!(test_i64, prop_i64, i64);
impl_prop!(test_f32, prop_f32, f32);
impl_prop!(test_f64, prop_f64, f64);
}
}
#[cfg(test)]
mod string_manual_build {
#[cfg(not(miri))] // slow.
@@ -1327,7 +1234,7 @@ mod roundtrip_vectors {
b.finish_minimal(vecend);
let buf = b.finished_data();
let got = <flatbuffers::ForwardsUOffset<flatbuffers::Vector<flatbuffers::ForwardsUOffset<&str>>>>::follow(buf, 0);
let got = unsafe { <flatbuffers::ForwardsUOffset<flatbuffers::Vector<flatbuffers::ForwardsUOffset<&str>>>>::follow(buf, 0) };
assert_eq!(got.len(), xs.len());
for i in 0..xs.len() {
@@ -1351,21 +1258,20 @@ mod roundtrip_vectors {
use alloc::vec::Vec;
fn prop(input: Vec<String>) {
let xs: Vec<&str> = input.iter().map(|s: &String| &s[..]).collect();
use flatbuffers::Follow;
let mut b = flatbuffers::FlatBufferBuilder::new();
let vecend = b.create_vector_of_strings(&xs[..]);
let xs: Vec<_> = input.iter().map(|s: &String| b.create_string(s)).collect();
let vecend = b.create_vector(&xs);
b.finish_minimal(vecend);
let buf = b.finished_data();
let got = <flatbuffers::ForwardsUOffset<flatbuffers::Vector<flatbuffers::ForwardsUOffset<&str>>>>::follow(buf, 0);
let got = unsafe { <flatbuffers::ForwardsUOffset<flatbuffers::Vector<flatbuffers::ForwardsUOffset<&str>>>>::follow(buf, 0) };
assert_eq!(got.len(), xs.len());
for i in 0..xs.len() {
assert_eq!(got.get(i), &xs[i][..]);
for (idx, s) in input.iter().enumerate() {
assert_eq!(got.get(idx), s);
}
}
@@ -1516,7 +1422,7 @@ mod roundtrip_table {
let table = {
let buf = builder.unfinished_data();
let loc = buf.len() as flatbuffers::UOffsetT - objects[i];
flatbuffers::Table::new(buf, loc as usize)
unsafe { flatbuffers::Table::new(buf, loc as usize) }
};
let fields_per_object = (lcg.next() % (max_fields_per_object as u64)) as flatbuffers::VOffsetT;
@@ -1528,19 +1434,21 @@ mod roundtrip_table {
let f = flatbuffers::field_index_to_field_offset(j);
match choice {
0 => { assert_eq!(bool_val, table.get::<bool>(f, Some(false)).unwrap()); }
1 => { assert_eq!(char_val, table.get::<i8>(f, Some(0)).unwrap()); }
2 => { assert_eq!(uchar_val, table.get::<u8>(f, Some(0)).unwrap()); }
3 => { assert_eq!(short_val, table.get::<i16>(f, Some(0)).unwrap()); }
4 => { assert_eq!(ushort_val, table.get::<u16>(f, Some(0)).unwrap()); }
5 => { assert_eq!(int_val, table.get::<i32>(f, Some(0)).unwrap()); }
6 => { assert_eq!(uint_val, table.get::<u32>(f, Some(0)).unwrap()); }
7 => { assert_eq!(long_val, table.get::<i64>(f, Some(0)).unwrap()); }
8 => { assert_eq!(ulong_val, table.get::<u64>(f, Some(0)).unwrap()); }
9 => { assert_eq!(float_val, table.get::<f32>(f, Some(0.0)).unwrap()); }
10 => { assert_eq!(double_val, table.get::<f64>(f, Some(0.0)).unwrap()); }
_ => { panic!("unknown choice: {}", choice); }
unsafe {
match choice {
0 => { assert_eq!(bool_val, table.get::<bool>(f, Some(false)).unwrap()); }
1 => { assert_eq!(char_val, table.get::<i8>(f, Some(0)).unwrap()); }
2 => { assert_eq!(uchar_val, table.get::<u8>(f, Some(0)).unwrap()); }
3 => { assert_eq!(short_val, table.get::<i16>(f, Some(0)).unwrap()); }
4 => { assert_eq!(ushort_val, table.get::<u16>(f, Some(0)).unwrap()); }
5 => { assert_eq!(int_val, table.get::<i32>(f, Some(0)).unwrap()); }
6 => { assert_eq!(uint_val, table.get::<u32>(f, Some(0)).unwrap()); }
7 => { assert_eq!(long_val, table.get::<i64>(f, Some(0)).unwrap()); }
8 => { assert_eq!(ulong_val, table.get::<u64>(f, Some(0)).unwrap()); }
9 => { assert_eq!(float_val, table.get::<f32>(f, Some(0.0)).unwrap()); }
10 => { assert_eq!(double_val, table.get::<f64>(f, Some(0.0)).unwrap()); }
_ => { panic!("unknown choice: {}", choice); }
}
}
}
}
@@ -1576,13 +1484,13 @@ mod roundtrip_table {
// use
let buf = b.finished_data();
let tab = <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(buf, 0);
let tab = unsafe { <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(buf, 0) };
for i in 0..xs.len() {
let v = tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<u8>>>(fi2fo(i as flatbuffers::VOffsetT), None);
let v = unsafe { tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<u8>>>(fi2fo(i as flatbuffers::VOffsetT), None) };
assert!(v.is_some());
let v2 = v.unwrap().safe_slice();
assert_eq!(v2, &xs[i][..]);
let v2 = v.unwrap();
assert_eq!(v2.bytes(), &xs[i]);
}
}
prop(vec![vec![1,2,3]]);
@@ -1613,10 +1521,10 @@ mod roundtrip_table {
// use
let buf = b.finished_data();
let tab = <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(buf, 0);
let tab = unsafe { <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(buf, 0) };
for i in 0..xs.len() {
let v = tab.get::<flatbuffers::ForwardsUOffset<&str>>(fi2fo(i as flatbuffers::VOffsetT), None);
let v = unsafe { tab.get::<flatbuffers::ForwardsUOffset<&str>>(fi2fo(i as flatbuffers::VOffsetT), None) };
assert_eq!(v, Some(&xs[i][..]));
}
}
@@ -1669,10 +1577,10 @@ mod roundtrip_table {
// use
let buf = b.finished_data();
let tab = <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(buf, 0);
let tab = unsafe { <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(buf, 0) };
for i in 0..vecs.len() {
let got = tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<T>>>(fi2fo(i as flatbuffers::VOffsetT), None);
let got = unsafe { tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<T>>>(fi2fo(i as flatbuffers::VOffsetT), None) };
assert!(got.is_some());
let got2 = got.unwrap();
let mut got3: Vec<T> = Vec::with_capacity(got2.len());
@@ -1774,9 +1682,9 @@ mod roundtrip_push_follow_scalars {
($fn_name:ident, $ty:ident) => (
fn $fn_name(x: $ty) {
let mut buf = vec![0u8; ::core::mem::size_of::<$ty>()];
x.push(&mut buf[..], &[][..]);
unsafe { x.push(&mut buf[..], 0) };
let fs: flatbuffers::FollowStart<$ty> = flatbuffers::FollowStart::new();
assert_eq!(fs.self_follow(&buf[..], 0), x);
assert_eq!(unsafe { fs.self_follow(&buf[..], 0) }, x);
}
)
}
@@ -2120,7 +2028,7 @@ mod builder_asserts {
struct foo { }
impl<'b> flatbuffers::Push for &'b foo {
type Output = foo;
fn push<'a>(&'a self, _dst: &'a mut [u8], _rest: &'a [u8]) { }
unsafe fn push<'a>(&'a self, _dst: &'a mut [u8], _written_len: usize) { }
}
let mut b = flatbuffers::FlatBufferBuilder::new();
b.push_slot_always(0, &foo{});
@@ -2173,18 +2081,17 @@ mod follow_impls {
}
}
}
impl flatbuffers::SafeSliceAccess for FooStruct {}
impl<'a> flatbuffers::Follow<'a> for FooStruct {
type Inner = &'a FooStruct;
#[inline(always)]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a FooStruct>::follow(buf, loc)
}
}
impl<'a> flatbuffers::Follow<'a> for &'a FooStruct {
type Inner = &'a FooStruct;
#[inline(always)]
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<FooStruct>(buf, loc)
}
}
@@ -2193,88 +2100,67 @@ mod follow_impls {
fn to_u8() {
let vec: Vec<u8> = vec![255, 3];
let fs: flatbuffers::FollowStart<u8> = flatbuffers::FollowStart::new();
assert_eq!(fs.self_follow(&vec[..], 1), 3);
assert_eq!(unsafe { fs.self_follow(&vec[..], 1) }, 3);
}
#[test]
fn to_u16() {
let vec: Vec<u8> = vec![255, 255, 3, 4];
let fs: flatbuffers::FollowStart<u16> = flatbuffers::FollowStart::new();
assert_eq!(fs.self_follow(&vec[..], 2), 1027);
assert_eq!(unsafe { fs.self_follow(&vec[..], 2) }, 1027);
}
#[test]
fn to_f32() {
let vec: Vec<u8> = vec![255, 255, 255, 255, /* start of value */ 208, 15, 73, 64];
let fs: flatbuffers::FollowStart<f32> = flatbuffers::FollowStart::new();
assert_eq!(fs.self_follow(&vec[..], 4), 3.14159);
assert_eq!(unsafe { fs.self_follow(&vec[..], 4) }, 3.14159);
}
#[test]
fn to_string() {
let vec: Vec<u8> = vec![255,255,255,255, 3, 0, 0, 0, 'f' as u8, 'o' as u8, 'o' as u8, 0];
let off: flatbuffers::FollowStart<&str> = flatbuffers::FollowStart::new();
assert_eq!(off.self_follow(&vec[..], 4), "foo");
assert_eq!(unsafe { off.self_follow(&vec[..], 4) }, "foo");
}
#[test]
fn to_byte_slice() {
let vec: Vec<u8> = vec![255, 255, 255, 255, 4, 0, 0, 0, 1, 2, 3, 4];
let off: flatbuffers::FollowStart<flatbuffers::Vector<u8>> = flatbuffers::FollowStart::new();
assert_eq!(off.self_follow(&vec[..], 4).safe_slice(), &[1, 2, 3, 4][..]);
}
#[test]
fn to_byte_vector() {
let vec: Vec<u8> = vec![255, 255, 255, 255, 4, 0, 0, 0, 1, 2, 3, 4];
let off: flatbuffers::FollowStart<flatbuffers::Vector<u8>> = flatbuffers::FollowStart::new();
assert_eq!(off.self_follow(&vec[..], 4).safe_slice(), &[1, 2, 3, 4][..]);
}
#[test]
fn to_byte_string_zero_teriminated() {
let vec: Vec<u8> = vec![255, 255, 255, 255, 3, 0, 0, 0, 1, 2, 3, 0];
let off: flatbuffers::FollowStart<flatbuffers::Vector<u8>> = flatbuffers::FollowStart::new();
assert_eq!(off.self_follow(&vec[..], 4).safe_slice(), &[1, 2, 3][..]);
assert_eq!(unsafe { off.self_follow(&vec[..], 4).bytes() }, &[1, 2, 3, 4][..]);
}
#[test]
fn to_vector_of_u16() {
let vec: Vec<u8> = vec![255, 255, 255, 255, 2, 0, 0, 0, 1, 2, 3, 4];
let off: flatbuffers::FollowStart<flatbuffers::Vector<u16>> = flatbuffers::FollowStart::new();
assert_eq!(off.self_follow(&vec[..], 4).len(), 2);
assert_eq!(off.self_follow(&vec[..], 4).get(0), 513);
assert_eq!(off.self_follow(&vec[..], 4).get(1), 1027);
assert_eq!(unsafe { off.self_follow(&vec[..], 4).len() }, 2);
assert_eq!(unsafe { off.self_follow(&vec[..], 4).get(0) }, 513);
assert_eq!(unsafe { off.self_follow(&vec[..], 4).get(1) }, 1027);
}
#[test]
fn to_struct() {
let vec: Vec<u8> = vec![255, 255, 255, 255, 1, 2, 3, 4];
let off: flatbuffers::FollowStart<&FooStruct> = flatbuffers::FollowStart::new();
assert_eq!(*off.self_follow(&vec[..], 4), FooStruct::new(1, 2, 1027));
assert_eq!(unsafe { *off.self_follow(&vec[..], 4) }, FooStruct::new(1, 2, 1027));
}
#[test]
fn to_vector_of_offset_to_string_elements() {
let buf: Vec<u8> = vec![/* vec len */ 1, 0, 0, 0, /* offset to string */ 4, 0, 0, 0, /* str length */ 3, 0, 0, 0, 'f' as u8, 'o' as u8, 'o' as u8, 0];
let s: flatbuffers::FollowStart<flatbuffers::Vector<flatbuffers::ForwardsUOffset<&str>>> = flatbuffers::FollowStart::new();
assert_eq!(s.self_follow(&buf[..], 0).len(), 1);
assert_eq!(s.self_follow(&buf[..], 0).get(0), "foo");
}
#[test]
fn to_slice_of_struct_elements() {
let buf: Vec<u8> = vec![1, 0, 0, 0, /* struct data */ 1, 2, 3, 4];
let fs: flatbuffers::FollowStart<flatbuffers::Vector<FooStruct>> = flatbuffers::FollowStart::new();
assert_eq!(fs.self_follow(&buf[..], 0).safe_slice(), &vec![FooStruct::new(1, 2, 1027)][..]);
assert_eq!(unsafe {s.self_follow(&buf[..], 0).len() }, 1);
assert_eq!(unsafe { s.self_follow(&buf[..], 0).get(0) }, "foo");
}
#[test]
fn to_vector_of_struct_elements() {
let buf: Vec<u8> = vec![1, 0, 0, 0, /* struct data */ 1, 2, 3, 4];
let fs: flatbuffers::FollowStart<flatbuffers::Vector<FooStruct>> = flatbuffers::FollowStart::new();
assert_eq!(fs.self_follow(&buf[..], 0).len(), 1);
assert_eq!(fs.self_follow(&buf[..], 0).get(0), &FooStruct::new(1, 2, 1027));
assert_eq!(unsafe { fs.self_follow(&buf[..], 0).len() }, 1);
assert_eq!(unsafe { fs.self_follow(&buf[..], 0).get(0) }, &FooStruct::new(1, 2, 1027));
}
#[test]
@@ -2288,8 +2174,10 @@ mod follow_impls {
// enter table
8, 0, 0, 0, // vtable location
];
let fs: flatbuffers::FollowStart<flatbuffers::ForwardsUOffset<flatbuffers::Table>> = flatbuffers::FollowStart::new();
assert_eq!(fs.self_follow(&buf[..], 0), flatbuffers::Table::new(&buf[..], 12));
unsafe {
let fs: flatbuffers::FollowStart<flatbuffers::ForwardsUOffset<flatbuffers::Table>> = flatbuffers::FollowStart::new();
assert_eq!(fs.self_follow(&buf[..], 0), flatbuffers::Table::new(&buf[..], 12));
}
}
#[test]
@@ -2305,9 +2193,11 @@ mod follow_impls {
10, 0, 0, 0, // vtable location
0, 99 // value (with padding)
];
let fs: flatbuffers::FollowStart<flatbuffers::ForwardsUOffset<flatbuffers::Table>> = flatbuffers::FollowStart::new();
let tab = fs.self_follow(&buf[..], 0);
assert_eq!(tab.get::<u8>(fi2fo(0), Some(123)), Some(99));
unsafe {
let fs: flatbuffers::FollowStart<flatbuffers::ForwardsUOffset<flatbuffers::Table>> = flatbuffers::FollowStart::new();
let tab = fs.self_follow(&buf[..], 0);
assert_eq!(tab.get::<u8>(fi2fo(0), Some(123)), Some(99));
}
}
#[test]
@@ -2321,9 +2211,11 @@ mod follow_impls {
// enter table
8, 0, 0, 0, // vtable location
];
let fs: flatbuffers::FollowStart<flatbuffers::ForwardsUOffset<flatbuffers::Table>> = flatbuffers::FollowStart::new();
let tab = fs.self_follow(&buf[..], 0);
assert_eq!(tab.get::<u8>(fi2fo(0), Some(123)), Some(123));
unsafe {
let fs: flatbuffers::FollowStart<flatbuffers::ForwardsUOffset<flatbuffers::Table>> = flatbuffers::FollowStart::new();
let tab = fs.self_follow(&buf[..], 0);
assert_eq!(tab.get::<u8>(fi2fo(0), Some(123)), Some(123));
}
}
#[test]
@@ -2338,9 +2230,11 @@ mod follow_impls {
// enter table
10, 0, 0, 0, // vtable location
];
let fs: flatbuffers::FollowStart<flatbuffers::ForwardsUOffset<flatbuffers::Table>> = flatbuffers::FollowStart::new();
let tab = fs.self_follow(&buf[..], 0);
assert_eq!(tab.get::<u8>(fi2fo(0), Some(123)), Some(123));
unsafe {
let fs: flatbuffers::FollowStart<flatbuffers::ForwardsUOffset<flatbuffers::Table>> = flatbuffers::FollowStart::new();
let tab = fs.self_follow(&buf[..], 0);
assert_eq!(tab.get::<u8>(fi2fo(0), Some(123)), Some(123));
}
}
#[test]
@@ -2360,15 +2254,17 @@ mod follow_impls {
// enter string
3, 0, 0, 0, 109, 111, 111, 0 // string length and contents
];
let tab = <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(&buf[..], 0);
assert_eq!(tab.get::<flatbuffers::ForwardsUOffset<&str>>(fi2fo(0), None), Some("moo"));
let byte_vec = tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<u8>>>(fi2fo(0), None).unwrap().safe_slice();
assert_eq!(byte_vec, &vec![109, 111, 111][..]);
let v = tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<u8>>>(fi2fo(0), None).unwrap();
assert_eq!(v.len(), 3);
assert_eq!(v.get(0), 109);
assert_eq!(v.get(1), 111);
assert_eq!(v.get(2), 111);
unsafe {
let tab = <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(&buf[..], 0);
assert_eq!(tab.get::<flatbuffers::ForwardsUOffset<&str>>(fi2fo(0), None), Some("moo"));
let byte_vec = tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<u8>>>(fi2fo(0), None).unwrap().bytes();
assert_eq!(byte_vec, &vec![109, 111, 111][..]);
let v = tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<u8>>>(fi2fo(0), None).unwrap();
assert_eq!(v.len(), 3);
assert_eq!(v.get(0), 109);
assert_eq!(v.get(1), 111);
assert_eq!(v.get(2), 111);
}
}
#[test]
@@ -2382,20 +2278,23 @@ mod follow_impls {
// enter table
8, 0, 0, 0, // vtable location
];
let tab = <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(&buf[..], 0);
assert_eq!(tab.get::<flatbuffers::ForwardsUOffset<&str>>(fi2fo(0), Some("abc")), Some("abc"));
#[cfg(target_endian = "little")]
{
assert_eq!(tab.get::<flatbuffers::ForwardsUOffset<&[u8]>>(fi2fo(0), Some(&vec![70, 71, 72][..])), Some(&vec![70, 71, 72][..]));
}
let default_vec_buf: Vec<u8> = vec![3, 0, 0, 0, 70, 71, 72, 0];
let default_vec = flatbuffers::Vector::new(&default_vec_buf[..], 0);
let v = tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<u8>>>(fi2fo(0), Some(default_vec)).unwrap();
assert_eq!(v.len(), 3);
assert_eq!(v.get(0), 70);
assert_eq!(v.get(1), 71);
assert_eq!(v.get(2), 72);
unsafe {
let tab = <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(&buf[..], 0);
assert_eq!(tab.get::<flatbuffers::ForwardsUOffset<&str>>(fi2fo(0), Some("abc")), Some("abc"));
#[cfg(target_endian = "little")]
{
assert_eq!(tab.get::<flatbuffers::ForwardsUOffset<&[u8]>>(fi2fo(0), Some(&vec![70, 71, 72][..])), Some(&vec![70, 71, 72][..]));
}
let default_vec_buf: Vec<u8> = vec![3, 0, 0, 0, 70, 71, 72, 0];
let default_vec = flatbuffers::Vector::new(&default_vec_buf[..], 0);
let v = tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<u8>>>(fi2fo(0), Some(default_vec)).unwrap();
assert_eq!(v.len(), 3);
assert_eq!(v.get(0), 70);
assert_eq!(v.get(1), 71);
assert_eq!(v.get(2), 72);
}
}
#[test]
@@ -2410,20 +2309,22 @@ mod follow_impls {
// enter table
10, 0, 0, 0, // vtable location
];
let tab = <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(&buf[..], 0);
assert_eq!(tab.get::<flatbuffers::ForwardsUOffset<&str>>(fi2fo(0), Some("abc")), Some("abc"));
#[cfg(target_endian = "little")]
{
assert_eq!(tab.get::<flatbuffers::ForwardsUOffset<&[u8]>>(fi2fo(0), Some(&vec![70, 71, 72][..])), Some(&vec![70, 71, 72][..]));
}
unsafe {
let tab = <flatbuffers::ForwardsUOffset<flatbuffers::Table>>::follow(&buf[..], 0);
assert_eq!(tab.get::<flatbuffers::ForwardsUOffset<&str>>(fi2fo(0), Some("abc")), Some("abc"));
#[cfg(target_endian = "little")]
{
assert_eq!(tab.get::<flatbuffers::ForwardsUOffset<&[u8]>>(fi2fo(0), Some(&vec![70, 71, 72][..])), Some(&vec![70, 71, 72][..]));
}
let default_vec_buf: Vec<u8> = vec![3, 0, 0, 0, 70, 71, 72, 0];
let default_vec = flatbuffers::Vector::new(&default_vec_buf[..], 0);
let v = tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<u8>>>(fi2fo(0), Some(default_vec)).unwrap();
assert_eq!(v.len(), 3);
assert_eq!(v.get(0), 70);
assert_eq!(v.get(1), 71);
assert_eq!(v.get(2), 72);
let default_vec_buf: Vec<u8> = vec![3, 0, 0, 0, 70, 71, 72, 0];
let default_vec = flatbuffers::Vector::new(&default_vec_buf[..], 0);
let v = tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<u8>>>(fi2fo(0), Some(default_vec)).unwrap();
assert_eq!(v.len(), 3);
assert_eq!(v.get(0), 70);
assert_eq!(v.get(1), 71);
assert_eq!(v.get(2), 72);
}
}
}
@@ -2923,10 +2824,8 @@ mod byte_layouts {
assert_eq!(::core::mem::size_of::<foo>(), 16);
impl<'b> flatbuffers::Push for &'b foo {
type Output = foo;
fn push<'a>(&'a self, dst: &'a mut [u8], _rest: &'a [u8]) {
let src = unsafe {
::core::slice::from_raw_parts(*self as *const foo as *const u8, ::core::mem::size_of::<foo>())
};
unsafe fn push<'a>(&'a self, dst: &'a mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(*self as *const foo as *const u8, ::core::mem::size_of::<foo>());
dst.copy_from_slice(src);
}
}