mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-26 09:52:40 +00:00
Generate better formatted Rust code (#8919)
* Cleans up Rust formatting * Regenerates generated schemas
This commit is contained in:
@@ -2,15 +2,18 @@
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
use super::*;
|
||||
|
||||
// struct ArrayStruct, aligned to 8
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub struct ArrayStruct(pub [u8; 160]);
|
||||
|
||||
impl Default for ArrayStruct {
|
||||
fn default() -> Self {
|
||||
Self([0; 160])
|
||||
}
|
||||
}
|
||||
|
||||
impl ::core::fmt::Debug for ArrayStruct {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
f.debug_struct("ArrayStruct")
|
||||
@@ -25,27 +28,34 @@ impl ::core::fmt::Debug for ArrayStruct {
|
||||
}
|
||||
|
||||
impl ::flatbuffers::SimpleToVerifyInSlice for ArrayStruct {}
|
||||
|
||||
impl<'a> ::flatbuffers::Follow<'a> for ArrayStruct {
|
||||
type Inner = &'a ArrayStruct;
|
||||
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe { <&'a ArrayStruct>::follow(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Follow<'a> for &'a ArrayStruct {
|
||||
type Inner = &'a ArrayStruct;
|
||||
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe { ::flatbuffers::follow_cast_ref::<ArrayStruct>(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b> ::flatbuffers::Push for ArrayStruct {
|
||||
type Output = ArrayStruct;
|
||||
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = unsafe { ::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, <Self as ::flatbuffers::Push>::size()) };
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alignment() -> ::flatbuffers::PushAlignment {
|
||||
::flatbuffers::PushAlignment::new(8)
|
||||
@@ -244,6 +254,7 @@ pub struct ArrayStructT {
|
||||
pub e: i32,
|
||||
pub f: [i64; 2],
|
||||
}
|
||||
|
||||
impl ArrayStructT {
|
||||
pub fn pack(&self) -> ArrayStruct {
|
||||
ArrayStruct::new(
|
||||
@@ -256,4 +267,3 @@ impl ArrayStructT {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
use super::*;
|
||||
pub enum ArrayTableOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub enum ArrayTableOffset {}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub struct ArrayTable<'a> {
|
||||
pub _tab: ::flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Follow<'a> for ArrayTable<'a> {
|
||||
type Inner = ArrayTable<'a>;
|
||||
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } }
|
||||
@@ -28,6 +30,7 @@ impl<'a> ArrayTable<'a> {
|
||||
pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self {
|
||||
ArrayTable { _tab: table }
|
||||
}
|
||||
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>(
|
||||
_fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>,
|
||||
@@ -67,9 +70,11 @@ impl ::flatbuffers::Verifiable for ArrayTable<'_> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ArrayTableArgs<'a> {
|
||||
pub a: Option<&'a ArrayStruct>,
|
||||
}
|
||||
|
||||
impl<'a> Default for ArrayTableArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
@@ -83,11 +88,13 @@ pub struct ArrayTableBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> {
|
||||
fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
|
||||
impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> ArrayTableBuilder<'a, 'b, A> {
|
||||
#[inline]
|
||||
pub fn add_a(&mut self, a: &ArrayStruct) {
|
||||
self.fbb_.push_slot_always::<&ArrayStruct>(ArrayTable::VT_A, a);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> ArrayTableBuilder<'a, 'b, A> {
|
||||
let start = _fbb.start_table();
|
||||
@@ -96,6 +103,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> ArrayTableBuilder<'a, 'b, A>
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn finish(self) -> ::flatbuffers::WIPOffset<ArrayTable<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
@@ -110,11 +118,13 @@ impl ::core::fmt::Debug for ArrayTable<'_> {
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ArrayTableT {
|
||||
pub a: Option<ArrayStructT>,
|
||||
}
|
||||
|
||||
impl Default for ArrayTableT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -122,6 +132,7 @@ impl Default for ArrayTableT {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ArrayTableT {
|
||||
pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(
|
||||
&self,
|
||||
@@ -134,66 +145,73 @@ impl ArrayTableT {
|
||||
})
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
|
||||
/// Verifies that a buffer of bytes contains a `ArrayTable`
|
||||
/// and returns it.
|
||||
/// Note that verification is still experimental and may not
|
||||
/// catch every error, or be maximally performant. For the
|
||||
/// previous, unchecked, behavior use
|
||||
/// `root_as_array_table_unchecked`.
|
||||
#[inline]
|
||||
pub fn root_as_array_table(buf: &[u8]) -> Result<ArrayTable<'_>, ::flatbuffers::InvalidFlatbuffer> {
|
||||
::flatbuffers::root::<ArrayTable>(buf)
|
||||
}
|
||||
#[inline]
|
||||
|
||||
/// Verifies that a buffer of bytes contains a size prefixed
|
||||
/// `ArrayTable` and returns it.
|
||||
/// Note that verification is still experimental and may not
|
||||
/// catch every error, or be maximally performant. For the
|
||||
/// previous, unchecked, behavior use
|
||||
/// `size_prefixed_root_as_array_table_unchecked`.
|
||||
#[inline]
|
||||
pub fn size_prefixed_root_as_array_table(buf: &[u8]) -> Result<ArrayTable<'_>, ::flatbuffers::InvalidFlatbuffer> {
|
||||
::flatbuffers::size_prefixed_root::<ArrayTable>(buf)
|
||||
}
|
||||
#[inline]
|
||||
|
||||
/// Verifies, with the given options, that a buffer of bytes
|
||||
/// contains a `ArrayTable` and returns it.
|
||||
/// Note that verification is still experimental and may not
|
||||
/// catch every error, or be maximally performant. For the
|
||||
/// previous, unchecked, behavior use
|
||||
/// `root_as_array_table_unchecked`.
|
||||
#[inline]
|
||||
pub fn root_as_array_table_with_opts<'b, 'o>(
|
||||
opts: &'o ::flatbuffers::VerifierOptions,
|
||||
buf: &'b [u8],
|
||||
) -> Result<ArrayTable<'b>, ::flatbuffers::InvalidFlatbuffer> {
|
||||
::flatbuffers::root_with_opts::<ArrayTable<'b>>(opts, buf)
|
||||
}
|
||||
#[inline]
|
||||
|
||||
/// Verifies, with the given verifier options, that a buffer of
|
||||
/// bytes contains a size prefixed `ArrayTable` and returns
|
||||
/// it. Note that verification is still experimental and may not
|
||||
/// catch every error, or be maximally performant. For the
|
||||
/// previous, unchecked, behavior use
|
||||
/// `root_as_array_table_unchecked`.
|
||||
#[inline]
|
||||
pub fn size_prefixed_root_as_array_table_with_opts<'b, 'o>(
|
||||
opts: &'o ::flatbuffers::VerifierOptions,
|
||||
buf: &'b [u8],
|
||||
) -> Result<ArrayTable<'b>, ::flatbuffers::InvalidFlatbuffer> {
|
||||
::flatbuffers::size_prefixed_root_with_opts::<ArrayTable<'b>>(opts, buf)
|
||||
}
|
||||
#[inline]
|
||||
|
||||
/// Assumes, without verification, that a buffer of bytes contains a ArrayTable and returns it.
|
||||
/// # Safety
|
||||
/// Callers must trust the given bytes do indeed contain a valid `ArrayTable`.
|
||||
#[inline]
|
||||
pub unsafe fn root_as_array_table_unchecked(buf: &[u8]) -> ArrayTable<'_> {
|
||||
unsafe { ::flatbuffers::root_unchecked::<ArrayTable>(buf) }
|
||||
}
|
||||
#[inline]
|
||||
|
||||
/// Assumes, without verification, that a buffer of bytes contains a size prefixed ArrayTable and returns it.
|
||||
/// # Safety
|
||||
/// Callers must trust the given bytes do indeed contain a valid size prefixed `ArrayTable`.
|
||||
#[inline]
|
||||
pub unsafe fn size_prefixed_root_as_array_table_unchecked(buf: &[u8]) -> ArrayTable<'_> {
|
||||
unsafe { ::flatbuffers::size_prefixed_root_unchecked::<ArrayTable>(buf) }
|
||||
}
|
||||
|
||||
pub const ARRAY_TABLE_IDENTIFIER: &str = "ARRT";
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -2,15 +2,18 @@
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
use super::*;
|
||||
|
||||
// struct NestedStruct, aligned to 8
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub struct NestedStruct(pub [u8; 32]);
|
||||
|
||||
impl Default for NestedStruct {
|
||||
fn default() -> Self {
|
||||
Self([0; 32])
|
||||
}
|
||||
}
|
||||
|
||||
impl ::core::fmt::Debug for NestedStruct {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
f.debug_struct("NestedStruct")
|
||||
@@ -23,27 +26,34 @@ impl ::core::fmt::Debug for NestedStruct {
|
||||
}
|
||||
|
||||
impl ::flatbuffers::SimpleToVerifyInSlice for NestedStruct {}
|
||||
|
||||
impl<'a> ::flatbuffers::Follow<'a> for NestedStruct {
|
||||
type Inner = &'a NestedStruct;
|
||||
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe { <&'a NestedStruct>::follow(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Follow<'a> for &'a NestedStruct {
|
||||
type Inner = &'a NestedStruct;
|
||||
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
unsafe { ::flatbuffers::follow_cast_ref::<NestedStruct>(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b> ::flatbuffers::Push for NestedStruct {
|
||||
type Output = NestedStruct;
|
||||
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = unsafe { ::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, <Self as ::flatbuffers::Push>::size()) };
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alignment() -> ::flatbuffers::PushAlignment {
|
||||
::flatbuffers::PushAlignment::new(8)
|
||||
@@ -176,6 +186,7 @@ pub struct NestedStructT {
|
||||
pub c: [TestEnum; 2],
|
||||
pub d: [i64; 2],
|
||||
}
|
||||
|
||||
impl NestedStructT {
|
||||
pub fn pack(&self) -> NestedStruct {
|
||||
NestedStruct::new(
|
||||
@@ -186,4 +197,3 @@ impl NestedStructT {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
use super::*;
|
||||
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MIN_TEST_ENUM: i8 = 0;
|
||||
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MAX_TEST_ENUM: i8 = 2;
|
||||
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub const ENUM_VALUES_TEST_ENUM: [TestEnum; 3] = [
|
||||
@@ -17,6 +20,7 @@ pub const ENUM_VALUES_TEST_ENUM: [TestEnum; 3] = [
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
#[repr(transparent)]
|
||||
pub struct TestEnum(pub i8);
|
||||
|
||||
#[allow(non_upper_case_globals)]
|
||||
impl TestEnum {
|
||||
pub const A: Self = Self(0);
|
||||
@@ -30,6 +34,7 @@ impl TestEnum {
|
||||
Self::B,
|
||||
Self::C,
|
||||
];
|
||||
|
||||
/// Returns the variant's name or "" if unknown.
|
||||
pub fn variant_name(self) -> Option<&'static str> {
|
||||
match self {
|
||||
@@ -40,6 +45,7 @@ impl TestEnum {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::core::fmt::Debug for TestEnum {
|
||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||
if let Some(name) = self.variant_name() {
|
||||
@@ -49,8 +55,10 @@ impl ::core::fmt::Debug for TestEnum {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ::flatbuffers::Follow<'a> for TestEnum {
|
||||
type Inner = Self;
|
||||
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = unsafe { ::flatbuffers::read_scalar_at::<i8>(buf, loc) };
|
||||
@@ -60,6 +68,7 @@ impl<'a> ::flatbuffers::Follow<'a> for TestEnum {
|
||||
|
||||
impl ::flatbuffers::Push for TestEnum {
|
||||
type Output = TestEnum;
|
||||
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
unsafe { ::flatbuffers::emplace_scalar::<i8>(dst, self.0) };
|
||||
@@ -68,10 +77,12 @@ impl ::flatbuffers::Push for TestEnum {
|
||||
|
||||
impl ::flatbuffers::EndianScalar for TestEnum {
|
||||
type Scalar = i8;
|
||||
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> i8 {
|
||||
self.0.to_le()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn from_little_endian(v: i8) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user