• 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_EQUIPMENT: 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_EQUIPMENT: u8 = 1;
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_EQUIPMENT: [Equipment; 2] = [
19   Equipment::NONE,
20   Equipment::Weapon,
21 ];
22 
23 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
24 #[repr(transparent)]
25 pub struct Equipment(pub u8);
26 #[allow(non_upper_case_globals)]
27 impl Equipment {
28   pub const NONE: Self = Self(0);
29   pub const Weapon: Self = Self(1);
30 
31   pub const ENUM_MIN: u8 = 0;
32   pub const ENUM_MAX: u8 = 1;
33   pub const ENUM_VALUES: &'static [Self] = &[
34     Self::NONE,
35     Self::Weapon,
36   ];
37   /// Returns the variant's name or "" if unknown.
variant_name(self) -> Option<&'static str>38   pub fn variant_name(self) -> Option<&'static str> {
39     match self {
40       Self::NONE => Some("NONE"),
41       Self::Weapon => Some("Weapon"),
42       _ => None,
43     }
44   }
45 }
46 impl core::fmt::Debug for Equipment {
fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result47   fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
48     if let Some(name) = self.variant_name() {
49       f.write_str(name)
50     } else {
51       f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
52     }
53   }
54 }
55 impl<'a> flatbuffers::Follow<'a> for Equipment {
56   type Inner = Self;
57   #[inline]
follow(buf: &'a [u8], loc: usize) -> Self::Inner58   fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
59     let b = unsafe {
60       flatbuffers::read_scalar_at::<u8>(buf, loc)
61     };
62     Self(b)
63   }
64 }
65 
66 impl flatbuffers::Push for Equipment {
67     type Output = Equipment;
68     #[inline]
push(&self, dst: &mut [u8], _rest: &[u8])69     fn push(&self, dst: &mut [u8], _rest: &[u8]) {
70         unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
71     }
72 }
73 
74 impl flatbuffers::EndianScalar for Equipment {
75   #[inline]
to_little_endian(self) -> Self76   fn to_little_endian(self) -> Self {
77     let b = u8::to_le(self.0);
78     Self(b)
79   }
80   #[inline]
81   #[allow(clippy::wrong_self_convention)]
from_little_endian(self) -> Self82   fn from_little_endian(self) -> Self {
83     let b = u8::from_le(self.0);
84     Self(b)
85   }
86 }
87 
88 impl<'a> flatbuffers::Verifiable for Equipment {
89   #[inline]
run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer>90   fn run_verifier(
91     v: &mut flatbuffers::Verifier, pos: usize
92   ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
93     use self::flatbuffers::Verifiable;
94     u8::run_verifier(v, pos)
95   }
96 }
97 
98 impl flatbuffers::SimpleToVerifyInSlice for Equipment {}
99 pub struct EquipmentUnionTableOffset {}
100 
101 #[allow(clippy::upper_case_acronyms)]
102 #[non_exhaustive]
103 #[derive(Debug, Clone, PartialEq)]
104 pub enum EquipmentT {
105   NONE,
106   Weapon(Box<WeaponT>),
107 }
108 impl Default for EquipmentT {
default() -> Self109   fn default() -> Self {
110     Self::NONE
111   }
112 }
113 impl EquipmentT {
equipment_type(&self) -> Equipment114   pub fn equipment_type(&self) -> Equipment {
115     match self {
116       Self::NONE => Equipment::NONE,
117       Self::Weapon(_) => Equipment::Weapon,
118     }
119   }
pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>120   pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
121     match self {
122       Self::NONE => None,
123       Self::Weapon(v) => Some(v.pack(fbb).as_union_value()),
124     }
125   }
126   /// If the union variant matches, return the owned WeaponT, setting the union to NONE.
take_weapon(&mut self) -> Option<Box<WeaponT>>127   pub fn take_weapon(&mut self) -> Option<Box<WeaponT>> {
128     if let Self::Weapon(_) = self {
129       let v = core::mem::replace(self, Self::NONE);
130       if let Self::Weapon(w) = v {
131         Some(w)
132       } else {
133         unreachable!()
134       }
135     } else {
136       None
137     }
138   }
139   /// If the union variant matches, return a reference to the WeaponT.
as_weapon(&self) -> Option<&WeaponT>140   pub fn as_weapon(&self) -> Option<&WeaponT> {
141     if let Self::Weapon(v) = self { Some(v.as_ref()) } else { None }
142   }
143   /// If the union variant matches, return a mutable reference to the WeaponT.
as_weapon_mut(&mut self) -> Option<&mut WeaponT>144   pub fn as_weapon_mut(&mut self) -> Option<&mut WeaponT> {
145     if let Self::Weapon(v) = self { Some(v.as_mut()) } else { None }
146   }
147 }
148