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