wow_world_base/inner/wrath/
item_quality.rs

1/// Auto generated from the original `wowm` in file [`wow_message_parser/wowm/world/social/social_common_3_3_5.wowm:491`](https://github.com/gtker/wow_messages/tree/main/wow_message_parser/wowm/world/social/social_common_3_3_5.wowm#L491):
2/// ```text
3/// enum ItemQuality : u8 {
4///     POOR = 0;
5///     NORMAL = 1;
6///     UNCOMMON = 2;
7///     RARE = 3;
8///     EPIC = 4;
9///     LEGENDARY = 5;
10///     ARTIFACT = 6;
11///     HEIRLOOM = 7;
12/// }
13/// ```
14#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Copy, Clone)]
15#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
16pub enum ItemQuality {
17    Poor,
18    Normal,
19    Uncommon,
20    Rare,
21    Epic,
22    Legendary,
23    Artifact,
24    Heirloom,
25}
26
27impl ItemQuality {
28    pub const fn as_int(&self) -> u8 {
29        match self {
30            Self::Poor => 0x0,
31            Self::Normal => 0x1,
32            Self::Uncommon => 0x2,
33            Self::Rare => 0x3,
34            Self::Epic => 0x4,
35            Self::Legendary => 0x5,
36            Self::Artifact => 0x6,
37            Self::Heirloom => 0x7,
38        }
39    }
40
41    pub const fn variants() -> [Self; 8] {
42        [
43            Self::Poor,
44            Self::Normal,
45            Self::Uncommon,
46            Self::Rare,
47            Self::Epic,
48            Self::Legendary,
49            Self::Artifact,
50            Self::Heirloom,
51        ]
52    }
53
54    pub const fn from_int(value: u8) -> Result<Self, crate::errors::EnumError> {
55        match value {
56            0 => Ok(Self::Poor),
57            1 => Ok(Self::Normal),
58            2 => Ok(Self::Uncommon),
59            3 => Ok(Self::Rare),
60            4 => Ok(Self::Epic),
61            5 => Ok(Self::Legendary),
62            6 => Ok(Self::Artifact),
63            7 => Ok(Self::Heirloom),
64            v => Err(crate::errors::EnumError::new(NAME, v as i128),)
65        }
66    }
67}
68
69#[cfg(feature = "print-testcase")]
70impl ItemQuality {
71    pub const fn as_test_case_value(&self) -> &'static str {
72        match self {
73            Self::Poor => "POOR",
74            Self::Normal => "NORMAL",
75            Self::Uncommon => "UNCOMMON",
76            Self::Rare => "RARE",
77            Self::Epic => "EPIC",
78            Self::Legendary => "LEGENDARY",
79            Self::Artifact => "ARTIFACT",
80            Self::Heirloom => "HEIRLOOM",
81        }
82    }
83
84}
85
86const NAME: &str = "ItemQuality";
87
88impl Default for ItemQuality {
89    fn default() -> Self {
90        Self::Poor
91    }
92}
93
94impl std::fmt::Display for ItemQuality {
95    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
96        match self {
97            Self::Poor => f.write_str("Poor"),
98            Self::Normal => f.write_str("Normal"),
99            Self::Uncommon => f.write_str("Uncommon"),
100            Self::Rare => f.write_str("Rare"),
101            Self::Epic => f.write_str("Epic"),
102            Self::Legendary => f.write_str("Legendary"),
103            Self::Artifact => f.write_str("Artifact"),
104            Self::Heirloom => f.write_str("Heirloom"),
105        }
106    }
107}
108
109impl TryFrom<u8> for ItemQuality {
110    type Error = crate::errors::EnumError;
111    fn try_from(value: u8) -> Result<Self, Self::Error> {
112        Self::from_int(value)
113    }
114}
115
116impl TryFrom<u16> for ItemQuality {
117    type Error = crate::errors::EnumError;
118    fn try_from(value: u16) -> 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<u32> for ItemQuality {
126    type Error = crate::errors::EnumError;
127    fn try_from(value: u32) -> Result<Self, Self::Error> {
128        TryInto::<u8>::try_into(value)
129            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
130            .try_into()
131    }
132}
133
134impl TryFrom<u64> for ItemQuality {
135    type Error = crate::errors::EnumError;
136    fn try_from(value: u64) -> Result<Self, Self::Error> {
137        TryInto::<u8>::try_into(value)
138            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
139            .try_into()
140    }
141}
142
143impl TryFrom<i8> for ItemQuality {
144    type Error = crate::errors::EnumError;
145    fn try_from(value: i8) -> Result<Self, Self::Error> {
146        let v = u8::from_le_bytes(value.to_le_bytes());
147        Self::from_int(v)
148    }
149}
150
151impl TryFrom<i16> for ItemQuality {
152    type Error = crate::errors::EnumError;
153    fn try_from(value: i16) -> 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<i32> for ItemQuality {
161    type Error = crate::errors::EnumError;
162    fn try_from(value: i32) -> Result<Self, Self::Error> {
163        TryInto::<u8>::try_into(value)
164            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
165            .try_into()
166    }
167}
168
169impl TryFrom<i64> for ItemQuality {
170    type Error = crate::errors::EnumError;
171    fn try_from(value: i64) -> Result<Self, Self::Error> {
172        TryInto::<u8>::try_into(value)
173            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
174            .try_into()
175    }
176}
177
178impl TryFrom<usize> for ItemQuality {
179    type Error = crate::errors::EnumError;
180    fn try_from(value: usize) -> Result<Self, Self::Error> {
181        TryInto::<u8>::try_into(value)
182            .map_err(|_| crate::errors::EnumError::new(NAME, value as i128))?
183            .try_into()
184    }
185}
186