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 = 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)] 18 pub 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)] 26 pub(crate) struct Any(pub u8); 27 #[allow(non_upper_case_globals)] 28 impl 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. variant_name(self) -> Option<&'static str>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 } 50 impl core::fmt::Debug for Any { fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result51 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 } 59 impl<'a> flatbuffers::Follow<'a> for Any { 60 type Inner = Self; 61 #[inline] follow(buf: &'a [u8], loc: usize) -> Self::Inner62 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 70 impl flatbuffers::Push for Any { 71 type Output = Any; 72 #[inline] push(&self, dst: &mut [u8], _rest: &[u8])73 fn push(&self, dst: &mut [u8], _rest: &[u8]) { 74 unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); } 75 } 76 } 77 78 impl flatbuffers::EndianScalar for Any { 79 #[inline] to_little_endian(self) -> Self80 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)] from_little_endian(self) -> Self86 fn from_little_endian(self) -> Self { 87 let b = u8::from_le(self.0); 88 Self(b) 89 } 90 } 91 92 impl<'a> flatbuffers::Verifiable for Any { 93 #[inline] run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>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 102 impl flatbuffers::SimpleToVerifyInSlice for Any {} 103 pub(crate) struct AnyUnionTableOffset {} 104 105 #[allow(clippy::upper_case_acronyms)] 106 #[non_exhaustive] 107 #[derive(Debug, Clone, PartialEq)] 108 pub(crate) enum AnyT { 109 NONE, 110 Game(Box<GameT>), 111 Annotations(Box<AnnotationsT>), 112 } 113 impl Default for AnyT { default() -> Self114 fn default() -> Self { 115 Self::NONE 116 } 117 } 118 impl AnyT { any_type(&self) -> Any119 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 } pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>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. take_game(&mut self) -> Option<Box<GameT>>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. as_game(&self) -> Option<&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. as_game_mut(&mut self) -> Option<&mut 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. take_annotations(&mut self) -> Option<Box<AnnotationsT>>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. as_annotations(&self) -> Option<&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. as_annotations_mut(&mut self) -> Option<&mut 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 } 176