Generate better formatted Rust code (#8919)

* Cleans up Rust formatting

* Regenerates generated schemas
This commit is contained in:
Cameron Mulhern
2026-03-04 21:49:46 -05:00
committed by GitHub
parent 9c383559e0
commit 08b6372a36
95 changed files with 2783 additions and 1062 deletions

View File

@@ -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_ENUM_IN_NESTED_NS: i8 = 0;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MAX_ENUM_IN_NESTED_NS: 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_ENUM_IN_NESTED_NS: [EnumInNestedNS; 3] = [
@@ -17,6 +20,7 @@ pub const ENUM_VALUES_ENUM_IN_NESTED_NS: [EnumInNestedNS; 3] = [
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct EnumInNestedNS(pub i8);
#[allow(non_upper_case_globals)]
impl EnumInNestedNS {
pub const A: Self = Self(0);
@@ -30,6 +34,7 @@ impl EnumInNestedNS {
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 EnumInNestedNS {
}
}
}
impl ::core::fmt::Debug for EnumInNestedNS {
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 EnumInNestedNS {
}
}
}
impl<'a> ::flatbuffers::Follow<'a> for EnumInNestedNS {
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 EnumInNestedNS {
impl ::flatbuffers::Push for EnumInNestedNS {
type Output = EnumInNestedNS;
#[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 EnumInNestedNS {
impl ::flatbuffers::EndianScalar for EnumInNestedNS {
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 {

View File

@@ -2,15 +2,18 @@
// @generated
extern crate alloc;
use super::*;
// struct StructInNestedNS, aligned to 4
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq)]
pub struct StructInNestedNS(pub [u8; 8]);
impl Default for StructInNestedNS {
fn default() -> Self {
Self([0; 8])
}
}
impl ::core::fmt::Debug for StructInNestedNS {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
f.debug_struct("StructInNestedNS")
@@ -21,27 +24,34 @@ impl ::core::fmt::Debug for StructInNestedNS {
}
impl ::flatbuffers::SimpleToVerifyInSlice for StructInNestedNS {}
impl<'a> ::flatbuffers::Follow<'a> for StructInNestedNS {
type Inner = &'a StructInNestedNS;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe { <&'a StructInNestedNS>::follow(buf, loc) }
}
}
impl<'a> ::flatbuffers::Follow<'a> for &'a StructInNestedNS {
type Inner = &'a StructInNestedNS;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
unsafe { ::flatbuffers::follow_cast_ref::<StructInNestedNS>(buf, loc) }
}
}
impl<'b> ::flatbuffers::Push for StructInNestedNS {
type Output = StructInNestedNS;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = unsafe { ::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, <Self as ::flatbuffers::Push>::size()) };
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> ::flatbuffers::PushAlignment {
::flatbuffers::PushAlignment::new(4)
@@ -144,6 +154,7 @@ pub struct StructInNestedNST {
pub a: i32,
pub b: i32,
}
impl StructInNestedNST {
pub fn pack(&self) -> StructInNestedNS {
StructInNestedNS::new(
@@ -152,4 +163,3 @@ impl StructInNestedNST {
)
}
}

View File

@@ -2,15 +2,17 @@
// @generated
extern crate alloc;
use super::*;
pub enum TableInNestedNSOffset {}
#[derive(Copy, Clone, PartialEq)]
pub enum TableInNestedNSOffset {}
#[derive(Copy, Clone, PartialEq)]
pub struct TableInNestedNS<'a> {
pub _tab: ::flatbuffers::Table<'a>,
}
impl<'a> ::flatbuffers::Follow<'a> for TableInNestedNS<'a> {
type Inner = TableInNestedNS<'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> TableInNestedNS<'a> {
pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self {
TableInNestedNS { _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>,
@@ -65,9 +68,11 @@ impl ::flatbuffers::Verifiable for TableInNestedNS<'_> {
Ok(())
}
}
pub struct TableInNestedNSArgs {
pub foo: i32,
}
impl<'a> Default for TableInNestedNSArgs {
#[inline]
fn default() -> Self {
@@ -81,11 +86,13 @@ pub struct TableInNestedNSBuilder<'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> TableInNestedNSBuilder<'a, 'b, A> {
#[inline]
pub fn add_foo(&mut self, foo: i32) {
self.fbb_.push_slot::<i32>(TableInNestedNS::VT_FOO, foo, 0);
}
#[inline]
pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> TableInNestedNSBuilder<'a, 'b, A> {
let start = _fbb.start_table();
@@ -94,6 +101,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> TableInNestedNSBuilder<'a, 'b
start_: start,
}
}
#[inline]
pub fn finish(self) -> ::flatbuffers::WIPOffset<TableInNestedNS<'a>> {
let o = self.fbb_.end_table(self.start_);
@@ -108,11 +116,13 @@ impl ::core::fmt::Debug for TableInNestedNS<'_> {
ds.finish()
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub struct TableInNestedNST {
pub foo: i32,
}
impl Default for TableInNestedNST {
fn default() -> Self {
Self {
@@ -120,6 +130,7 @@ impl Default for TableInNestedNST {
}
}
}
impl TableInNestedNST {
pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(
&self,

View File

@@ -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_UNION_IN_NESTED_NS: u8 = 0;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MAX_UNION_IN_NESTED_NS: u8 = 1;
#[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_UNION_IN_NESTED_NS: [UnionInNestedNS; 2] = [
@@ -16,6 +19,7 @@ pub const ENUM_VALUES_UNION_IN_NESTED_NS: [UnionInNestedNS; 2] = [
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub struct UnionInNestedNS(pub u8);
#[allow(non_upper_case_globals)]
impl UnionInNestedNS {
pub const NONE: Self = Self(0);
@@ -27,6 +31,7 @@ impl UnionInNestedNS {
Self::NONE,
Self::TableInNestedNS,
];
/// Returns the variant's name or "" if unknown.
pub fn variant_name(self) -> Option<&'static str> {
match self {
@@ -36,6 +41,7 @@ impl UnionInNestedNS {
}
}
}
impl ::core::fmt::Debug for UnionInNestedNS {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
if let Some(name) = self.variant_name() {
@@ -45,8 +51,10 @@ impl ::core::fmt::Debug for UnionInNestedNS {
}
}
}
impl<'a> ::flatbuffers::Follow<'a> for UnionInNestedNS {
type Inner = Self;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe { ::flatbuffers::read_scalar_at::<u8>(buf, loc) };
@@ -56,6 +64,7 @@ impl<'a> ::flatbuffers::Follow<'a> for UnionInNestedNS {
impl ::flatbuffers::Push for UnionInNestedNS {
type Output = UnionInNestedNS;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
unsafe { ::flatbuffers::emplace_scalar::<u8>(dst, self.0) };
@@ -64,10 +73,12 @@ impl ::flatbuffers::Push for UnionInNestedNS {
impl ::flatbuffers::EndianScalar for UnionInNestedNS {
type Scalar = u8;
#[inline]
fn to_little_endian(self) -> u8 {
self.0.to_le()
}
#[inline]
#[allow(clippy::wrong_self_convention)]
fn from_little_endian(v: u8) -> Self {
@@ -86,6 +97,7 @@ impl<'a> ::flatbuffers::Verifiable for UnionInNestedNS {
}
impl ::flatbuffers::SimpleToVerifyInSlice for UnionInNestedNS {}
pub struct UnionInNestedNSUnionTableOffset {}
#[allow(clippy::upper_case_acronyms)]
@@ -95,11 +107,13 @@ pub enum UnionInNestedNST {
NONE,
TableInNestedNS(alloc::boxed::Box<TableInNestedNST>),
}
impl Default for UnionInNestedNST {
fn default() -> Self {
Self::NONE
}
}
impl UnionInNestedNST {
pub fn union_in_nested_ns_type(&self) -> UnionInNestedNS {
match self {
@@ -107,12 +121,14 @@ impl UnionInNestedNST {
Self::TableInNestedNS(_) => UnionInNestedNS::TableInNestedNS,
}
}
pub fn pack<'b, A: ::flatbuffers::Allocator + 'b>(&self, fbb: &mut ::flatbuffers::FlatBufferBuilder<'b, A>) -> Option<::flatbuffers::WIPOffset<::flatbuffers::UnionWIPOffset>> {
match self {
Self::NONE => None,
Self::TableInNestedNS(v) => Some(v.pack(fbb).as_union_value()),
}
}
/// If the union variant matches, return the owned TableInNestedNST, setting the union to NONE.
pub fn take_table_in_nested_ns(&mut self) -> Option<alloc::boxed::Box<TableInNestedNST>> {
if let Self::TableInNestedNS(_) = self {
@@ -126,12 +142,15 @@ impl UnionInNestedNST {
None
}
}
/// If the union variant matches, return a reference to the TableInNestedNST.
pub fn as_table_in_nested_ns(&self) -> Option<&TableInNestedNST> {
if let Self::TableInNestedNS(v) = self { Some(v.as_ref()) } else { None }
}
/// If the union variant matches, return a mutable reference to the TableInNestedNST.
pub fn as_table_in_nested_ns_mut(&mut self) -> Option<&mut TableInNestedNST> {
if let Self::TableInNestedNS(v) = self { Some(v.as_mut()) } else { None }
}
}