• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
78     let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
79     Self(b)
80   }
81 }
82 
83 impl flatbuffers::Push for Any {
84     type Output = Any;
85     #[inline]
push(&self, dst: &mut [u8], _written_len: usize)86     unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
87         flatbuffers::emplace_scalar::<u8>(dst, self.0);
88     }
89 }
90 
91 impl flatbuffers::EndianScalar for Any {
92   type Scalar = u8;
93   #[inline]
to_little_endian(self) -> u894   fn to_little_endian(self) -> u8 {
95     self.0.to_le()
96   }
97   #[inline]
98   #[allow(clippy::wrong_self_convention)]
from_little_endian(v: u8) -> Self99   fn from_little_endian(v: u8) -> Self {
100     let b = u8::from_le(v);
101     Self(b)
102   }
103 }
104 
105 impl<'a> flatbuffers::Verifiable for Any {
106   #[inline]
run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>107   fn run_verifier(
108     v: &mut flatbuffers::Verifier, pos: usize
109   ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
110     use self::flatbuffers::Verifiable;
111     u8::run_verifier(v, pos)
112   }
113 }
114 
115 impl flatbuffers::SimpleToVerifyInSlice for Any {}
116 pub struct AnyUnionTableOffset {}
117 
118 #[allow(clippy::upper_case_acronyms)]
119 #[non_exhaustive]
120 #[derive(Debug, Clone, PartialEq)]
121 pub enum AnyT {
122   NONE,
123   Monster(Box<MonsterT>),
124   TestSimpleTableWithEnum(Box<TestSimpleTableWithEnumT>),
125   MyGameExample2Monster(Box<super::example_2::MonsterT>),
126 }
127 impl Default for AnyT {
default() -> Self128   fn default() -> Self {
129     Self::NONE
130   }
131 }
132 impl AnyT {
any_type(&self) -> Any133   pub fn any_type(&self) -> Any {
134     match self {
135       Self::NONE => Any::NONE,
136       Self::Monster(_) => Any::Monster,
137       Self::TestSimpleTableWithEnum(_) => Any::TestSimpleTableWithEnum,
138       Self::MyGameExample2Monster(_) => Any::MyGame_Example2_Monster,
139     }
140   }
pack<'b, A: flatbuffers::Allocator + 'b>(&self, fbb: &mut flatbuffers::FlatBufferBuilder<'b, A>) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>141   pub fn pack<'b, A: flatbuffers::Allocator + 'b>(&self, fbb: &mut flatbuffers::FlatBufferBuilder<'b, A>) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
142     match self {
143       Self::NONE => None,
144       Self::Monster(v) => Some(v.pack(fbb).as_union_value()),
145       Self::TestSimpleTableWithEnum(v) => Some(v.pack(fbb).as_union_value()),
146       Self::MyGameExample2Monster(v) => Some(v.pack(fbb).as_union_value()),
147     }
148   }
149   /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
take_monster(&mut self) -> Option<Box<MonsterT>>150   pub fn take_monster(&mut self) -> Option<Box<MonsterT>> {
151     if let Self::Monster(_) = self {
152       let v = core::mem::replace(self, Self::NONE);
153       if let Self::Monster(w) = v {
154         Some(w)
155       } else {
156         unreachable!()
157       }
158     } else {
159       None
160     }
161   }
162   /// If the union variant matches, return a reference to the MonsterT.
as_monster(&self) -> Option<&MonsterT>163   pub fn as_monster(&self) -> Option<&MonsterT> {
164     if let Self::Monster(v) = self { Some(v.as_ref()) } else { None }
165   }
166   /// If the union variant matches, return a mutable reference to the MonsterT.
as_monster_mut(&mut self) -> Option<&mut MonsterT>167   pub fn as_monster_mut(&mut self) -> Option<&mut MonsterT> {
168     if let Self::Monster(v) = self { Some(v.as_mut()) } else { None }
169   }
170   /// 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>>171   pub fn take_test_simple_table_with_enum(&mut self) -> Option<Box<TestSimpleTableWithEnumT>> {
172     if let Self::TestSimpleTableWithEnum(_) = self {
173       let v = core::mem::replace(self, Self::NONE);
174       if let Self::TestSimpleTableWithEnum(w) = v {
175         Some(w)
176       } else {
177         unreachable!()
178       }
179     } else {
180       None
181     }
182   }
183   /// If the union variant matches, return a reference to the TestSimpleTableWithEnumT.
as_test_simple_table_with_enum(&self) -> Option<&TestSimpleTableWithEnumT>184   pub fn as_test_simple_table_with_enum(&self) -> Option<&TestSimpleTableWithEnumT> {
185     if let Self::TestSimpleTableWithEnum(v) = self { Some(v.as_ref()) } else { None }
186   }
187   /// If the union variant matches, return a mutable reference to the TestSimpleTableWithEnumT.
as_test_simple_table_with_enum_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT>188   pub fn as_test_simple_table_with_enum_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT> {
189     if let Self::TestSimpleTableWithEnum(v) = self { Some(v.as_mut()) } else { None }
190   }
191   /// 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>>192   pub fn take_my_game_example_2_monster(&mut self) -> Option<Box<super::example_2::MonsterT>> {
193     if let Self::MyGameExample2Monster(_) = self {
194       let v = core::mem::replace(self, Self::NONE);
195       if let Self::MyGameExample2Monster(w) = v {
196         Some(w)
197       } else {
198         unreachable!()
199       }
200     } else {
201       None
202     }
203   }
204   /// 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>205   pub fn as_my_game_example_2_monster(&self) -> Option<&super::example_2::MonsterT> {
206     if let Self::MyGameExample2Monster(v) = self { Some(v.as_ref()) } else { None }
207   }
208   /// 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>209   pub fn as_my_game_example_2_monster_mut(&mut self) -> Option<&mut super::example_2::MonsterT> {
210     if let Self::MyGameExample2Monster(v) = self { Some(v.as_mut()) } else { None }
211   }
212 }
213