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