"Fossies" - the Fresh Open Source Software Archive 
Member "flatbuffers-23.1.21/tests/monster_test_serialize/my_game/example/any_ambiguous_aliases_generated.rs" (21 Jan 2023, 6678 Bytes) of package /linux/misc/flatbuffers-23.1.21.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Rust source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
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_AMBIGUOUS_ALIASES: 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_AMBIGUOUS_ALIASES: 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_AMBIGUOUS_ALIASES: [AnyAmbiguousAliases; 4] = [
21 AnyAmbiguousAliases::NONE,
22 AnyAmbiguousAliases::M1,
23 AnyAmbiguousAliases::M2,
24 AnyAmbiguousAliases::M3,
25 ];
26
27 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
28 #[repr(transparent)]
29 pub struct AnyAmbiguousAliases(pub u8);
30 #[allow(non_upper_case_globals)]
31 impl AnyAmbiguousAliases {
32 pub const NONE: Self = Self(0);
33 pub const M1: Self = Self(1);
34 pub const M2: Self = Self(2);
35 pub const M3: 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::M1,
42 Self::M2,
43 Self::M3,
44 ];
45 /// Returns the variant's name or "" if unknown.
46 pub fn variant_name(self) -> Option<&'static str> {
47 match self {
48 Self::NONE => Some("NONE"),
49 Self::M1 => Some("M1"),
50 Self::M2 => Some("M2"),
51 Self::M3 => Some("M3"),
52 _ => None,
53 }
54 }
55 }
56 impl core::fmt::Debug for AnyAmbiguousAliases {
57 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 AnyAmbiguousAliases {
66 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
67 where
68 S: Serializer,
69 {
70 serializer.serialize_unit_variant("AnyAmbiguousAliases", self.0 as u32, self.variant_name().unwrap())
71 }
72 }
73
74 impl<'a> flatbuffers::Follow<'a> for AnyAmbiguousAliases {
75 type Inner = Self;
76 #[inline]
77 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 AnyAmbiguousAliases {
84 type Output = AnyAmbiguousAliases;
85 #[inline]
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 AnyAmbiguousAliases {
92 type Scalar = u8;
93 #[inline]
94 fn to_little_endian(self) -> u8 {
95 self.0.to_le()
96 }
97 #[inline]
98 #[allow(clippy::wrong_self_convention)]
99 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 AnyAmbiguousAliases {
106 #[inline]
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 AnyAmbiguousAliases {}
116 pub struct AnyAmbiguousAliasesUnionTableOffset {}
117
118 #[allow(clippy::upper_case_acronyms)]
119 #[non_exhaustive]
120 #[derive(Debug, Clone, PartialEq)]
121 pub enum AnyAmbiguousAliasesT {
122 NONE,
123 M1(Box<MonsterT>),
124 M2(Box<MonsterT>),
125 M3(Box<MonsterT>),
126 }
127 impl Default for AnyAmbiguousAliasesT {
128 fn default() -> Self {
129 Self::NONE
130 }
131 }
132 impl AnyAmbiguousAliasesT {
133 pub fn any_ambiguous_aliases_type(&self) -> AnyAmbiguousAliases {
134 match self {
135 Self::NONE => AnyAmbiguousAliases::NONE,
136 Self::M1(_) => AnyAmbiguousAliases::M1,
137 Self::M2(_) => AnyAmbiguousAliases::M2,
138 Self::M3(_) => AnyAmbiguousAliases::M3,
139 }
140 }
141 pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
142 match self {
143 Self::NONE => None,
144 Self::M1(v) => Some(v.pack(fbb).as_union_value()),
145 Self::M2(v) => Some(v.pack(fbb).as_union_value()),
146 Self::M3(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.
150 pub fn take_m1(&mut self) -> Option<Box<MonsterT>> {
151 if let Self::M1(_) = self {
152 let v = core::mem::replace(self, Self::NONE);
153 if let Self::M1(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.
163 pub fn as_m1(&self) -> Option<&MonsterT> {
164 if let Self::M1(v) = self { Some(v.as_ref()) } else { None }
165 }
166 /// If the union variant matches, return a mutable reference to the MonsterT.
167 pub fn as_m1_mut(&mut self) -> Option<&mut MonsterT> {
168 if let Self::M1(v) = self { Some(v.as_mut()) } else { None }
169 }
170 /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
171 pub fn take_m2(&mut self) -> Option<Box<MonsterT>> {
172 if let Self::M2(_) = self {
173 let v = core::mem::replace(self, Self::NONE);
174 if let Self::M2(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 MonsterT.
184 pub fn as_m2(&self) -> Option<&MonsterT> {
185 if let Self::M2(v) = self { Some(v.as_ref()) } else { None }
186 }
187 /// If the union variant matches, return a mutable reference to the MonsterT.
188 pub fn as_m2_mut(&mut self) -> Option<&mut MonsterT> {
189 if let Self::M2(v) = self { Some(v.as_mut()) } else { None }
190 }
191 /// If the union variant matches, return the owned MonsterT, setting the union to NONE.
192 pub fn take_m3(&mut self) -> Option<Box<MonsterT>> {
193 if let Self::M3(_) = self {
194 let v = core::mem::replace(self, Self::NONE);
195 if let Self::M3(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 MonsterT.
205 pub fn as_m3(&self) -> Option<&MonsterT> {
206 if let Self::M3(v) = self { Some(v.as_ref()) } else { None }
207 }
208 /// If the union variant matches, return a mutable reference to the MonsterT.
209 pub fn as_m3_mut(&mut self) -> Option<&mut MonsterT> {
210 if let Self::M3(v) = self { Some(v.as_mut()) } else { None }
211 }
212 }