1 // automatically generated by the FlatBuffers compiler, do not modify 2 // @generated 3 extern crate alloc; 4 extern crate flatbuffers; 5 use alloc::boxed::Box; 6 use alloc::string::{String, ToString}; 7 use alloc::vec::Vec; 8 use core::mem; 9 use core::cmp::Ordering; 10 use self::flatbuffers::{EndianScalar, Follow}; 11 use super::*; 12 #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] 13 pub const ENUM_MIN_ANY: u8 = 0; 14 #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] 15 pub const ENUM_MAX_ANY: u8 = 3; 16 #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] 17 #[allow(non_camel_case_types)] 18 pub const ENUM_VALUES_ANY: [Any; 4] = [ 19 Any::NONE, 20 Any::Monster, 21 Any::TestSimpleTableWithEnum, 22 Any::MyGame_Example2_Monster, 23 ]; 24 25 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] 26 #[repr(transparent)] 27 pub struct Any(pub u8); 28 #[allow(non_upper_case_globals)] 29 impl Any { 30 pub const NONE: Self = Self(0); 31 pub const Monster: Self = Self(1); 32 pub const TestSimpleTableWithEnum: Self = Self(2); 33 pub const MyGame_Example2_Monster: Self = Self(3); 34 35 pub const ENUM_MIN: u8 = 0; 36 pub const ENUM_MAX: u8 = 3; 37 pub const ENUM_VALUES: &'static [Self] = &[ 38 Self::NONE, 39 Self::Monster, 40 Self::TestSimpleTableWithEnum, 41 Self::MyGame_Example2_Monster, 42 ]; 43 /// Returns the variant's name or "" if unknown. variant_name(self) -> Option<&'static str>44 pub fn variant_name(self) -> Option<&'static str> { 45 match self { 46 Self::NONE => Some("NONE"), 47 Self::Monster => Some("Monster"), 48 Self::TestSimpleTableWithEnum => Some("TestSimpleTableWithEnum"), 49 Self::MyGame_Example2_Monster => Some("MyGame_Example2_Monster"), 50 _ => None, 51 } 52 } 53 } 54 impl core::fmt::Debug for Any { fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result55 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 56 if let Some(name) = self.variant_name() { 57 f.write_str(name) 58 } else { 59 f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0)) 60 } 61 } 62 } 63 impl<'a> flatbuffers::Follow<'a> for Any { 64 type Inner = Self; 65 #[inline] follow(buf: &'a [u8], loc: usize) -> Self::Inner66 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { 67 let b = unsafe { 68 flatbuffers::read_scalar_at::<u8>(buf, loc) 69 }; 70 Self(b) 71 } 72 } 73 74 impl flatbuffers::Push for Any { 75 type Output = Any; 76 #[inline] push(&self, dst: &mut [u8], _rest: &[u8])77 fn push(&self, dst: &mut [u8], _rest: &[u8]) { 78 unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); } 79 } 80 } 81 82 impl flatbuffers::EndianScalar for Any { 83 #[inline] to_little_endian(self) -> Self84 fn to_little_endian(self) -> Self { 85 let b = u8::to_le(self.0); 86 Self(b) 87 } 88 #[inline] 89 #[allow(clippy::wrong_self_convention)] from_little_endian(self) -> Self90 fn from_little_endian(self) -> Self { 91 let b = u8::from_le(self.0); 92 Self(b) 93 } 94 } 95 96 impl<'a> flatbuffers::Verifiable for Any { 97 #[inline] run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>98 fn run_verifier( 99 v: &mut flatbuffers::Verifier, pos: usize 100 ) -> Result<(), flatbuffers::InvalidFlatbuffer> { 101 use self::flatbuffers::Verifiable; 102 u8::run_verifier(v, pos) 103 } 104 } 105 106 impl flatbuffers::SimpleToVerifyInSlice for Any {} 107 pub struct AnyUnionTableOffset {} 108 109 #[allow(clippy::upper_case_acronyms)] 110 #[non_exhaustive] 111 #[derive(Debug, Clone, PartialEq)] 112 pub enum AnyT { 113 NONE, 114 Monster(Box<MonsterT>), 115 TestSimpleTableWithEnum(Box<TestSimpleTableWithEnumT>), 116 MyGameExample2Monster(Box<super::example_2::MonsterT>), 117 } 118 impl Default for AnyT { default() -> Self119 fn default() -> Self { 120 Self::NONE 121 } 122 } 123 impl AnyT { any_type(&self) -> Any124 pub fn any_type(&self) -> Any { 125 match self { 126 Self::NONE => Any::NONE, 127 Self::Monster(_) => Any::Monster, 128 Self::TestSimpleTableWithEnum(_) => Any::TestSimpleTableWithEnum, 129 Self::MyGameExample2Monster(_) => Any::MyGame_Example2_Monster, 130 } 131 } pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>132 pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> { 133 match self { 134 Self::NONE => None, 135 Self::Monster(v) => Some(v.pack(fbb).as_union_value()), 136 Self::TestSimpleTableWithEnum(v) => Some(v.pack(fbb).as_union_value()), 137 Self::MyGameExample2Monster(v) => Some(v.pack(fbb).as_union_value()), 138 } 139 } 140 /// If the union variant matches, return the owned MonsterT, setting the union to NONE. take_monster(&mut self) -> Option<Box<MonsterT>>141 pub fn take_monster(&mut self) -> Option<Box<MonsterT>> { 142 if let Self::Monster(_) = self { 143 let v = core::mem::replace(self, Self::NONE); 144 if let Self::Monster(w) = v { 145 Some(w) 146 } else { 147 unreachable!() 148 } 149 } else { 150 None 151 } 152 } 153 /// If the union variant matches, return a reference to the MonsterT. as_monster(&self) -> Option<&MonsterT>154 pub fn as_monster(&self) -> Option<&MonsterT> { 155 if let Self::Monster(v) = self { Some(v.as_ref()) } else { None } 156 } 157 /// If the union variant matches, return a mutable reference to the MonsterT. as_monster_mut(&mut self) -> Option<&mut MonsterT>158 pub fn as_monster_mut(&mut self) -> Option<&mut MonsterT> { 159 if let Self::Monster(v) = self { Some(v.as_mut()) } else { None } 160 } 161 /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE. take_test_simple_table_with_enum(&mut self) -> Option<Box<TestSimpleTableWithEnumT>>162 pub fn take_test_simple_table_with_enum(&mut self) -> Option<Box<TestSimpleTableWithEnumT>> { 163 if let Self::TestSimpleTableWithEnum(_) = self { 164 let v = core::mem::replace(self, Self::NONE); 165 if let Self::TestSimpleTableWithEnum(w) = v { 166 Some(w) 167 } else { 168 unreachable!() 169 } 170 } else { 171 None 172 } 173 } 174 /// If the union variant matches, return a reference to the TestSimpleTableWithEnumT. as_test_simple_table_with_enum(&self) -> Option<&TestSimpleTableWithEnumT>175 pub fn as_test_simple_table_with_enum(&self) -> Option<&TestSimpleTableWithEnumT> { 176 if let Self::TestSimpleTableWithEnum(v) = self { Some(v.as_ref()) } else { None } 177 } 178 /// If the union variant matches, return a mutable reference to the TestSimpleTableWithEnumT. as_test_simple_table_with_enum_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT>179 pub fn as_test_simple_table_with_enum_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT> { 180 if let Self::TestSimpleTableWithEnum(v) = self { Some(v.as_mut()) } else { None } 181 } 182 /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE. take_my_game_example_2_monster(&mut self) -> Option<Box<super::example_2::MonsterT>>183 pub fn take_my_game_example_2_monster(&mut self) -> Option<Box<super::example_2::MonsterT>> { 184 if let Self::MyGameExample2Monster(_) = self { 185 let v = core::mem::replace(self, Self::NONE); 186 if let Self::MyGameExample2Monster(w) = v { 187 Some(w) 188 } else { 189 unreachable!() 190 } 191 } else { 192 None 193 } 194 } 195 /// If the union variant matches, return a reference to the super::example_2::MonsterT. as_my_game_example_2_monster(&self) -> Option<&super::example_2::MonsterT>196 pub fn as_my_game_example_2_monster(&self) -> Option<&super::example_2::MonsterT> { 197 if let Self::MyGameExample2Monster(v) = self { Some(v.as_ref()) } else { None } 198 } 199 /// If the union variant matches, return a mutable reference to the super::example_2::MonsterT. as_my_game_example_2_monster_mut(&mut self) -> Option<&mut super::example_2::MonsterT>200 pub fn as_my_game_example_2_monster_mut(&mut self) -> Option<&mut super::example_2::MonsterT> { 201 if let Self::MyGameExample2Monster(v) = self { Some(v.as_mut()) } else { None } 202 } 203 } 204