wow_world_base/inner/shared/
buyback_slot_vanilla_tbc_wrath.rs1#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Copy, Clone)]
20#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
21pub enum BuybackSlot {
22 Slot1,
23 Slot2,
24 Slot3,
25 Slot4,
26 Slot5,
27 Slot6,
28 Slot7,
29 Slot8,
30 Slot9,
31 Slot10,
32 Slot11,
33 Slot12,
34 Slot13,
35}
36
37impl BuybackSlot {
38 pub const fn as_int(&self) -> u32 {
39 match self {
40 Self::Slot1 => 0x45,
41 Self::Slot2 => 0x46,
42 Self::Slot3 => 0x47,
43 Self::Slot4 => 0x48,
44 Self::Slot5 => 0x49,
45 Self::Slot6 => 0x4a,
46 Self::Slot7 => 0x4b,
47 Self::Slot8 => 0x4c,
48 Self::Slot9 => 0x4d,
49 Self::Slot10 => 0x4e,
50 Self::Slot11 => 0x4f,
51 Self::Slot12 => 0x50,
52 Self::Slot13 => 0x51,
53 }
54 }
55
56 pub const fn variants() -> [Self; 13] {
57 [
58 Self::Slot1,
59 Self::Slot2,
60 Self::Slot3,
61 Self::Slot4,
62 Self::Slot5,
63 Self::Slot6,
64 Self::Slot7,
65 Self::Slot8,
66 Self::Slot9,
67 Self::Slot10,
68 Self::Slot11,
69 Self::Slot12,
70 Self::Slot13,
71 ]
72 }
73
74 pub const fn from_int(value: u32) -> Result<Self, crate::errors::EnumError> {
75 match value {
76 69 => Ok(Self::Slot1),
77 70 => Ok(Self::Slot2),
78 71 => Ok(Self::Slot3),
79 72 => Ok(Self::Slot4),
80 73 => Ok(Self::Slot5),
81 74 => Ok(Self::Slot6),
82 75 => Ok(Self::Slot7),
83 76 => Ok(Self::Slot8),
84 77 => Ok(Self::Slot9),
85 78 => Ok(Self::Slot10),
86 79 => Ok(Self::Slot11),
87 80 => Ok(Self::Slot12),
88 81 => Ok(Self::Slot13),
89 v => Err(crate::errors::EnumError::new(NAME, v as i128),)
90 }
91 }
92}
93
94#[cfg(feature = "print-testcase")]
95impl BuybackSlot {
96 pub const fn as_test_case_value(&self) -> &'static str {
97 match self {
98 Self::Slot1 => "SLOT1",
99 Self::Slot2 => "SLOT2",
100 Self::Slot3 => "SLOT3",
101 Self::Slot4 => "SLOT4",
102 Self::Slot5 => "SLOT5",
103 Self::Slot6 => "SLOT6",
104 Self::Slot7 => "SLOT7",
105 Self::Slot8 => "SLOT8",
106 Self::Slot9 => "SLOT9",
107 Self::Slot10 => "SLOT10",
108 Self::Slot11 => "SLOT11",
109 Self::Slot12 => "SLOT12",
110 Self::Slot13 => "SLOT13",
111 }
112 }
113
114}
115
116const NAME: &str = "BuybackSlot";
117
118impl Default for BuybackSlot {
119 fn default() -> Self {
120 Self::Slot1
121 }
122}
123
124impl std::fmt::Display for BuybackSlot {
125 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
126 match self {
127 Self::Slot1 => f.write_str("Slot1"),
128 Self::Slot2 => f.write_str("Slot2"),
129 Self::Slot3 => f.write_str("Slot3"),
130 Self::Slot4 => f.write_str("Slot4"),
131 Self::Slot5 => f.write_str("Slot5"),
132 Self::Slot6 => f.write_str("Slot6"),
133 Self::Slot7 => f.write_str("Slot7"),
134 Self::Slot8 => f.write_str("Slot8"),
135 Self::Slot9 => f.write_str("Slot9"),
136 Self::Slot10 => f.write_str("Slot10"),
137 Self::Slot11 => f.write_str("Slot11"),
138 Self::Slot12 => f.write_str("Slot12"),
139 Self::Slot13 => f.write_str("Slot13"),
140 }
141 }
142}
143
144impl TryFrom<u32> for BuybackSlot {
145 type Error = crate::errors::EnumError;
146 fn try_from(value: u32) -> Result<Self, Self::Error> {
147 Self::from_int(value)
148 }
149}
150
151impl TryFrom<u8> for BuybackSlot {
152 type Error = crate::errors::EnumError;
153 fn try_from(value: u8) -> Result<Self, Self::Error> {
154 Self::from_int(value.into())
155 }
156}
157
158impl TryFrom<u16> for BuybackSlot {
159 type Error = crate::errors::EnumError;
160 fn try_from(value: u16) -> Result<Self, Self::Error> {
161 Self::from_int(value.into())
162 }
163}
164
165impl TryFrom<u64> for BuybackSlot {
166 type Error = crate::errors::EnumError;
167 fn try_from(value: u64) -> Result<Self, Self::Error> {
168 TryInto::<u32>::try_into(value)
169 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
170 .try_into()
171 }
172}
173
174impl TryFrom<i8> for BuybackSlot {
175 type Error = crate::errors::EnumError;
176 fn try_from(value: i8) -> Result<Self, Self::Error> {
177 TryInto::<u32>::try_into(value)
178 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
179 .try_into()
180 }
181}
182
183impl TryFrom<i16> for BuybackSlot {
184 type Error = crate::errors::EnumError;
185 fn try_from(value: i16) -> Result<Self, Self::Error> {
186 TryInto::<u32>::try_into(value)
187 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
188 .try_into()
189 }
190}
191
192impl TryFrom<i32> for BuybackSlot {
193 type Error = crate::errors::EnumError;
194 fn try_from(value: i32) -> Result<Self, Self::Error> {
195 let v = u32::from_le_bytes(value.to_le_bytes());
196 Self::from_int(v)
197 }
198}
199
200impl TryFrom<i64> for BuybackSlot {
201 type Error = crate::errors::EnumError;
202 fn try_from(value: i64) -> Result<Self, Self::Error> {
203 TryInto::<u32>::try_into(value)
204 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
205 .try_into()
206 }
207}
208
209impl TryFrom<usize> for BuybackSlot {
210 type Error = crate::errors::EnumError;
211 fn try_from(value: usize) -> Result<Self, Self::Error> {
212 TryInto::<u32>::try_into(value)
213 .map_err(|_| crate::errors::EnumError::new(NAME, value as i128))?
214 .try_into()
215 }
216}
217