wow_world_base/inner/shared/
mail_type_vanilla_tbc_wrath.rs1#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Copy, Clone)]
12#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
13pub enum MailType {
14 Normal,
15 Auction,
16 Creature,
18 Gameobject,
20 Item,
22}
23
24impl MailType {
25 pub const fn as_int(&self) -> u8 {
26 match self {
27 Self::Normal => 0x0,
28 Self::Auction => 0x2,
29 Self::Creature => 0x3,
30 Self::Gameobject => 0x4,
31 Self::Item => 0x5,
32 }
33 }
34
35 pub const fn variants() -> [Self; 5] {
36 [
37 Self::Normal,
38 Self::Auction,
39 Self::Creature,
40 Self::Gameobject,
41 Self::Item,
42 ]
43 }
44
45 pub const fn from_int(value: u8) -> Result<Self, crate::errors::EnumError> {
46 match value {
47 0 => Ok(Self::Normal),
48 2 => Ok(Self::Auction),
49 3 => Ok(Self::Creature),
50 4 => Ok(Self::Gameobject),
51 5 => Ok(Self::Item),
52 v => Err(crate::errors::EnumError::new(NAME, v as i128),)
53 }
54 }
55}
56
57#[cfg(feature = "print-testcase")]
58impl MailType {
59 pub const fn as_test_case_value(&self) -> &'static str {
60 match self {
61 Self::Normal => "NORMAL",
62 Self::Auction => "AUCTION",
63 Self::Creature => "CREATURE",
64 Self::Gameobject => "GAMEOBJECT",
65 Self::Item => "ITEM",
66 }
67 }
68
69}
70
71const NAME: &str = "MailType";
72
73impl Default for MailType {
74 fn default() -> Self {
75 Self::Normal
76 }
77}
78
79impl std::fmt::Display for MailType {
80 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81 match self {
82 Self::Normal => f.write_str("Normal"),
83 Self::Auction => f.write_str("Auction"),
84 Self::Creature => f.write_str("Creature"),
85 Self::Gameobject => f.write_str("Gameobject"),
86 Self::Item => f.write_str("Item"),
87 }
88 }
89}
90
91impl TryFrom<u8> for MailType {
92 type Error = crate::errors::EnumError;
93 fn try_from(value: u8) -> Result<Self, Self::Error> {
94 Self::from_int(value)
95 }
96}
97
98impl TryFrom<u16> for MailType {
99 type Error = crate::errors::EnumError;
100 fn try_from(value: u16) -> Result<Self, Self::Error> {
101 TryInto::<u8>::try_into(value)
102 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
103 .try_into()
104 }
105}
106
107impl TryFrom<u32> for MailType {
108 type Error = crate::errors::EnumError;
109 fn try_from(value: u32) -> Result<Self, Self::Error> {
110 TryInto::<u8>::try_into(value)
111 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
112 .try_into()
113 }
114}
115
116impl TryFrom<u64> for MailType {
117 type Error = crate::errors::EnumError;
118 fn try_from(value: u64) -> Result<Self, Self::Error> {
119 TryInto::<u8>::try_into(value)
120 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
121 .try_into()
122 }
123}
124
125impl TryFrom<i8> for MailType {
126 type Error = crate::errors::EnumError;
127 fn try_from(value: i8) -> Result<Self, Self::Error> {
128 let v = u8::from_le_bytes(value.to_le_bytes());
129 Self::from_int(v)
130 }
131}
132
133impl TryFrom<i16> for MailType {
134 type Error = crate::errors::EnumError;
135 fn try_from(value: i16) -> Result<Self, Self::Error> {
136 TryInto::<u8>::try_into(value)
137 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
138 .try_into()
139 }
140}
141
142impl TryFrom<i32> for MailType {
143 type Error = crate::errors::EnumError;
144 fn try_from(value: i32) -> Result<Self, Self::Error> {
145 TryInto::<u8>::try_into(value)
146 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
147 .try_into()
148 }
149}
150
151impl TryFrom<i64> for MailType {
152 type Error = crate::errors::EnumError;
153 fn try_from(value: i64) -> Result<Self, Self::Error> {
154 TryInto::<u8>::try_into(value)
155 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
156 .try_into()
157 }
158}
159
160impl TryFrom<usize> for MailType {
161 type Error = crate::errors::EnumError;
162 fn try_from(value: usize) -> Result<Self, Self::Error> {
163 TryInto::<u8>::try_into(value)
164 .map_err(|_| crate::errors::EnumError::new(NAME, value as i128))?
165 .try_into()
166 }
167}
168