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_AB: i8 = 0;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MAX_AB: i8 = 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_AB: [AB; 2] = [
@@ -16,6 +19,7 @@ pub const ENUM_VALUES_AB: [AB; 2] = [
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub(crate) struct AB(pub i8);
#[allow(non_upper_case_globals)]
impl AB {
pub const A: Self = Self(0);
@@ -27,6 +31,7 @@ impl AB {
Self::A,
Self::B,
];
/// Returns the variant's name or "" if unknown.
pub fn variant_name(self) -> Option<&'static str> {
match self {
@@ -36,6 +41,7 @@ impl AB {
}
}
}
impl ::core::fmt::Debug for AB {
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 AB {
}
}
}
impl<'a> ::flatbuffers::Follow<'a> for AB {
type Inner = Self;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe { ::flatbuffers::read_scalar_at::<i8>(buf, loc) };
@@ -56,6 +64,7 @@ impl<'a> ::flatbuffers::Follow<'a> for AB {
impl ::flatbuffers::Push for AB {
type Output = AB;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
unsafe { ::flatbuffers::emplace_scalar::<i8>(dst, self.0) };
@@ -64,10 +73,12 @@ impl ::flatbuffers::Push for AB {
impl ::flatbuffers::EndianScalar for AB {
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,17 @@
// @generated
extern crate alloc;
use super::*;
pub(crate) enum AnnotationsOffset {}
#[derive(Copy, Clone, PartialEq)]
pub(crate) enum AnnotationsOffset {}
#[derive(Copy, Clone, PartialEq)]
pub(crate) struct Annotations<'a> {
pub _tab: ::flatbuffers::Table<'a>,
}
impl<'a> ::flatbuffers::Follow<'a> for Annotations<'a> {
type Inner = Annotations<'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> Annotations<'a> {
pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self {
Annotations { _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 Annotations<'_> {
Ok(())
}
}
pub(crate) struct AnnotationsArgs {
pub value: i32,
}
impl<'a> Default for AnnotationsArgs {
#[inline]
fn default() -> Self {
@@ -81,11 +86,13 @@ pub(crate) struct AnnotationsBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + '
fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>,
start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>,
}
impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> AnnotationsBuilder<'a, 'b, A> {
#[inline]
pub fn add_value(&mut self, value: i32) {
self.fbb_.push_slot::<i32>(Annotations::VT_VALUE, value, 0);
}
#[inline]
pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> AnnotationsBuilder<'a, 'b, A> {
let start = _fbb.start_table();
@@ -94,6 +101,7 @@ impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> AnnotationsBuilder<'a, 'b, A>
start_: start,
}
}
#[inline]
pub fn finish(self) -> ::flatbuffers::WIPOffset<Annotations<'a>> {
let o = self.fbb_.end_table(self.start_);
@@ -108,11 +116,13 @@ impl ::core::fmt::Debug for Annotations<'_> {
ds.finish()
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct AnnotationsT {
pub value: i32,
}
impl Default for AnnotationsT {
fn default() -> Self {
Self {
@@ -120,6 +130,7 @@ impl Default for AnnotationsT {
}
}
}
impl AnnotationsT {
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_ANY: u8 = 0;
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MAX_ANY: u8 = 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_ANY: [Any; 3] = [
@@ -17,6 +20,7 @@ pub const ENUM_VALUES_ANY: [Any; 3] = [
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[repr(transparent)]
pub(crate) struct Any(pub u8);
#[allow(non_upper_case_globals)]
impl Any {
pub const NONE: Self = Self(0);
@@ -30,6 +34,7 @@ impl Any {
Self::Game,
Self::Annotations,
];
/// Returns the variant's name or "" if unknown.
pub fn variant_name(self) -> Option<&'static str> {
match self {
@@ -40,6 +45,7 @@ impl Any {
}
}
}
impl ::core::fmt::Debug for Any {
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 Any {
}
}
}
impl<'a> ::flatbuffers::Follow<'a> for Any {
type Inner = Self;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = unsafe { ::flatbuffers::read_scalar_at::<u8>(buf, loc) };
@@ -60,6 +68,7 @@ impl<'a> ::flatbuffers::Follow<'a> for Any {
impl ::flatbuffers::Push for Any {
type Output = Any;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
unsafe { ::flatbuffers::emplace_scalar::<u8>(dst, self.0) };
@@ -68,10 +77,12 @@ impl ::flatbuffers::Push for Any {
impl ::flatbuffers::EndianScalar for Any {
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 {
@@ -90,6 +101,7 @@ impl<'a> ::flatbuffers::Verifiable for Any {
}
impl ::flatbuffers::SimpleToVerifyInSlice for Any {}
pub(crate) struct AnyUnionTableOffset {}
#[allow(clippy::upper_case_acronyms)]
@@ -100,11 +112,13 @@ pub(crate) enum AnyT {
Game(alloc::boxed::Box<GameT>),
Annotations(alloc::boxed::Box<AnnotationsT>),
}
impl Default for AnyT {
fn default() -> Self {
Self::NONE
}
}
impl AnyT {
pub fn any_type(&self) -> Any {
match self {
@@ -113,6 +127,7 @@ impl AnyT {
Self::Annotations(_) => Any::Annotations,
}
}
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,
@@ -120,6 +135,7 @@ impl AnyT {
Self::Annotations(v) => Some(v.pack(fbb).as_union_value()),
}
}
/// If the union variant matches, return the owned GameT, setting the union to NONE.
pub fn take_game(&mut self) -> Option<alloc::boxed::Box<GameT>> {
if let Self::Game(_) = self {
@@ -133,14 +149,17 @@ impl AnyT {
None
}
}
/// If the union variant matches, return a reference to the GameT.
pub fn as_game(&self) -> Option<&GameT> {
if let Self::Game(v) = self { Some(v.as_ref()) } else { None }
}
/// If the union variant matches, return a mutable reference to the GameT.
pub fn as_game_mut(&mut self) -> Option<&mut GameT> {
if let Self::Game(v) = self { Some(v.as_mut()) } else { None }
}
/// If the union variant matches, return the owned AnnotationsT, setting the union to NONE.
pub fn take_annotations(&mut self) -> Option<alloc::boxed::Box<AnnotationsT>> {
if let Self::Annotations(_) = self {
@@ -154,12 +173,15 @@ impl AnyT {
None
}
}
/// If the union variant matches, return a reference to the AnnotationsT.
pub fn as_annotations(&self) -> Option<&AnnotationsT> {
if let Self::Annotations(v) = self { Some(v.as_ref()) } else { None }
}
/// If the union variant matches, return a mutable reference to the AnnotationsT.
pub fn as_annotations_mut(&mut self) -> Option<&mut AnnotationsT> {
if let Self::Annotations(v) = self { Some(v.as_mut()) } else { None }
}
}

View File

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

View File

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