1// automatically generated by the FlatBuffers compiler, do not modify
2// @generated
3extern crate alloc;
4extern crate flatbuffers;
5use alloc::boxed::Box;
6use alloc::string::{String, ToString};
7use alloc::vec::Vec;
8use core::mem;
9use core::cmp::Ordering;
10use self::flatbuffers::{EndianScalar, Follow};
11use super::*;
12#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
13pub const ENUM_MIN_ANY_UNIQUE_ALIASES: u8 = 0;
14#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
15pub const ENUM_MAX_ANY_UNIQUE_ALIASES: 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)]
18pub const ENUM_VALUES_ANY_UNIQUE_ALIASES: [AnyUniqueAliases; 4] = [
19 AnyUniqueAliases::NONE,
20 AnyUniqueAliases::M,
21 AnyUniqueAliases::TS,
22 AnyUniqueAliases::M2,
23];
24
25#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
26#[repr(transparent)]
27pub struct AnyUniqueAliases(pub u8);
28#[allow(non_upper_case_globals)]
29impl AnyUniqueAliases {
30 pub const NONE: Self = Self(0);
31 pub const M: Self = Self(1);
32 pub const TS: Self = Self(2);
33 pub const M2: 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::M,
40 Self::TS,
41 Self::M2,
42 ];
43 /// Returns the variant's name or "" if unknown.
44 pub fn variant_name(self) -> Option<&'static str> {
45 match self {
46 Self::NONE => Some("NONE"),
47 Self::M => Some("M"),
48 Self::TS => Some("TS"),
49 Self::M2 => Some("M2"),
50 _ => None,
51 }
52 }
53}
54impl core::fmt::Debug for AnyUniqueAliases {
55 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}
63impl<'a> flatbuffers::Follow<'a> for AnyUniqueAliases {
64 type Inner = Self;
65 #[inline]
66 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
72impl flatbuffers::Push for AnyUniqueAliases {
73 type Output = AnyUniqueAliases;
74 #[inline]
75 unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
76 flatbuffers::emplace_scalar::<u8>(dst, self.0);
77 }
78}
79
80impl flatbuffers::EndianScalar for AnyUniqueAliases {
81 type Scalar = u8;
82 #[inline]
83 fn to_little_endian(self) -> u8 {
84 self.0.to_le()
85 }
86 #[inline]
87 #[allow(clippy::wrong_self_convention)]
88 fn from_little_endian(v: u8) -> Self {
89 let b = u8::from_le(v);
90 Self(b)
91 }
92}
93
94impl<'a> flatbuffers::Verifiable for AnyUniqueAliases {
95 #[inline]
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
104impl flatbuffers::SimpleToVerifyInSlice for AnyUniqueAliases {}
105pub struct AnyUniqueAliasesUnionTableOffset {}
106
107#[allow(clippy::upper_case_acronyms)]
108#[non_exhaustive]
109#[derive(Debug, Clone, PartialEq)]
110pub enum AnyUniqueAliasesT {
111 NONE,
112 M(Box<MonsterT>),
113 TS(Box<TestSimpleTableWithEnumT>),
114 M2(Box<super::example_2::MonsterT>),
115}
116impl Default for AnyUniqueAliasesT {
117 fn default() -> Self {
118 Self::NONE
119 }
120}
121impl AnyUniqueAliasesT {
122 pub fn any_unique_aliases_type(&self) -> AnyUniqueAliases {
123 match self {
124 Self::NONE => AnyUniqueAliases::NONE,
125 Self::M(_) => AnyUniqueAliases::M,
126 Self::TS(_) => AnyUniqueAliases::TS,
127 Self::M2(_) => AnyUniqueAliases::M2,
128 }
129 }
130 pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
131 match self {
132 Self::NONE => None,
133 Self::M(v) => Some(v.pack(fbb).as_union_value()),
134 Self::TS(v) => Some(v.pack(fbb).as_union_value()),
135 Self::M2(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.
139 pub fn take_m(&mut self) -> Option<Box<MonsterT>> {
140 if let Self::M(_) = self {
141 let v = core::mem::replace(self, Self::NONE);
142 if let Self::M(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.
152 pub fn as_m(&self) -> Option<&MonsterT> {
153 if let Self::M(v) = self { Some(v.as_ref()) } else { None }
154 }
155 /// If the union variant matches, return a mutable reference to the MonsterT.
156 pub fn as_m_mut(&mut self) -> Option<&mut MonsterT> {
157 if let Self::M(v) = self { Some(v.as_mut()) } else { None }
158 }
159 /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE.
160 pub fn take_ts(&mut self) -> Option<Box<TestSimpleTableWithEnumT>> {
161 if let Self::TS(_) = self {
162 let v = core::mem::replace(self, Self::NONE);
163 if let Self::TS(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.
173 pub fn as_ts(&self) -> Option<&TestSimpleTableWithEnumT> {
174 if let Self::TS(v) = self { Some(v.as_ref()) } else { None }
175 }
176 /// If the union variant matches, return a mutable reference to the TestSimpleTableWithEnumT.
177 pub fn as_ts_mut(&mut self) -> Option<&mut TestSimpleTableWithEnumT> {
178 if let Self::TS(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.
181 pub fn take_m2(&mut self) -> Option<Box<super::example_2::MonsterT>> {
182 if let Self::M2(_) = self {
183 let v = core::mem::replace(self, Self::NONE);
184 if let Self::M2(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.
194 pub fn as_m2(&self) -> Option<&super::example_2::MonsterT> {
195 if let Self::M2(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.
198 pub fn as_m2_mut(&mut self) -> Option<&mut super::example_2::MonsterT> {
199 if let Self::M2(v) = self { Some(v.as_mut()) } else { None }
200 }
201}
View as plain text