blob: c3049a08dd9d2df116e36c78f2e38f5c01a6d594 [file] [log] [blame]
Austin Schuh2dd86a92022-09-14 21:19:23 -07001// 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: 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: u8 = 2;
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: [Any; 3] = [
19 Any::NONE,
20 Any::Game,
21 Any::Annotations,
22];
23
24#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
25#[repr(transparent)]
26pub(crate) struct Any(pub u8);
27#[allow(non_upper_case_globals)]
28impl Any {
29 pub const NONE: Self = Self(0);
30 pub const Game: Self = Self(1);
31 pub const Annotations: Self = Self(2);
32
33 pub const ENUM_MIN: u8 = 0;
34 pub const ENUM_MAX: u8 = 2;
35 pub const ENUM_VALUES: &'static [Self] = &[
36 Self::NONE,
37 Self::Game,
38 Self::Annotations,
39 ];
40 /// Returns the variant's name or "" if unknown.
41 pub fn variant_name(self) -> Option<&'static str> {
42 match self {
43 Self::NONE => Some("NONE"),
44 Self::Game => Some("Game"),
45 Self::Annotations => Some("Annotations"),
46 _ => None,
47 }
48 }
49}
50impl core::fmt::Debug for Any {
51 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
52 if let Some(name) = self.variant_name() {
53 f.write_str(name)
54 } else {
55 f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
56 }
57 }
58}
59impl<'a> flatbuffers::Follow<'a> for Any {
60 type Inner = Self;
61 #[inline]
62 fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
63 let b = unsafe {
64 flatbuffers::read_scalar_at::<u8>(buf, loc)
65 };
66 Self(b)
67 }
68}
69
70impl flatbuffers::Push for Any {
71 type Output = Any;
72 #[inline]
73 fn push(&self, dst: &mut [u8], _rest: &[u8]) {
74 unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
75 }
76}
77
78impl flatbuffers::EndianScalar for Any {
79 #[inline]
80 fn to_little_endian(self) -> Self {
81 let b = u8::to_le(self.0);
82 Self(b)
83 }
84 #[inline]
85 #[allow(clippy::wrong_self_convention)]
86 fn from_little_endian(self) -> Self {
87 let b = u8::from_le(self.0);
88 Self(b)
89 }
90}
91
92impl<'a> flatbuffers::Verifiable for Any {
93 #[inline]
94 fn run_verifier(
95 v: &mut flatbuffers::Verifier, pos: usize
96 ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
97 use self::flatbuffers::Verifiable;
98 u8::run_verifier(v, pos)
99 }
100}
101
102impl flatbuffers::SimpleToVerifyInSlice for Any {}
103pub(crate) struct AnyUnionTableOffset {}
104
105#[allow(clippy::upper_case_acronyms)]
106#[non_exhaustive]
107#[derive(Debug, Clone, PartialEq)]
108pub(crate) enum AnyT {
109 NONE,
110 Game(Box<GameT>),
111 Annotations(Box<AnnotationsT>),
112}
113impl Default for AnyT {
114 fn default() -> Self {
115 Self::NONE
116 }
117}
118impl AnyT {
119 pub fn any_type(&self) -> Any {
120 match self {
121 Self::NONE => Any::NONE,
122 Self::Game(_) => Any::Game,
123 Self::Annotations(_) => Any::Annotations,
124 }
125 }
126 pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
127 match self {
128 Self::NONE => None,
129 Self::Game(v) => Some(v.pack(fbb).as_union_value()),
130 Self::Annotations(v) => Some(v.pack(fbb).as_union_value()),
131 }
132 }
133 /// If the union variant matches, return the owned GameT, setting the union to NONE.
134 pub fn take_game(&mut self) -> Option<Box<GameT>> {
135 if let Self::Game(_) = self {
136 let v = core::mem::replace(self, Self::NONE);
137 if let Self::Game(w) = v {
138 Some(w)
139 } else {
140 unreachable!()
141 }
142 } else {
143 None
144 }
145 }
146 /// If the union variant matches, return a reference to the GameT.
147 pub fn as_game(&self) -> Option<&GameT> {
148 if let Self::Game(v) = self { Some(v.as_ref()) } else { None }
149 }
150 /// If the union variant matches, return a mutable reference to the GameT.
151 pub fn as_game_mut(&mut self) -> Option<&mut GameT> {
152 if let Self::Game(v) = self { Some(v.as_mut()) } else { None }
153 }
154 /// If the union variant matches, return the owned AnnotationsT, setting the union to NONE.
155 pub fn take_annotations(&mut self) -> Option<Box<AnnotationsT>> {
156 if let Self::Annotations(_) = self {
157 let v = core::mem::replace(self, Self::NONE);
158 if let Self::Annotations(w) = v {
159 Some(w)
160 } else {
161 unreachable!()
162 }
163 } else {
164 None
165 }
166 }
167 /// If the union variant matches, return a reference to the AnnotationsT.
168 pub fn as_annotations(&self) -> Option<&AnnotationsT> {
169 if let Self::Annotations(v) = self { Some(v.as_ref()) } else { None }
170 }
171 /// If the union variant matches, return a mutable reference to the AnnotationsT.
172 pub fn as_annotations_mut(&mut self) -> Option<&mut AnnotationsT> {
173 if let Self::Annotations(v) = self { Some(v.as_mut()) } else { None }
174 }
175}