wow_world_base/inner/vanilla/
addon_type.rs

1/// Auto generated from the original `wowm` in file [`wow_message_parser/wowm/world/login_logout/smsg_addon_info.wowm:1`](https://github.com/gtker/wow_messages/tree/main/wow_message_parser/wowm/world/login_logout/smsg_addon_info.wowm#L1):
2/// ```text
3/// enum AddonType : u8 {
4///     BANNED = 0;
5///     ENABLED = 1;
6///     BLIZZARD = 2;
7/// }
8/// ```
9#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Copy, Clone)]
10#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
11pub enum AddonType {
12    Banned,
13    /// Shows addon in list. Probably intended for player-created addons.
14    Enabled,
15    /// Hides addon from list.
16    Blizzard,
17}
18
19impl AddonType {
20    pub const fn as_int(&self) -> u8 {
21        match self {
22            Self::Banned => 0x0,
23            Self::Enabled => 0x1,
24            Self::Blizzard => 0x2,
25        }
26    }
27
28    pub const fn variants() -> [Self; 3] {
29        [
30            Self::Banned,
31            Self::Enabled,
32            Self::Blizzard,
33        ]
34    }
35
36    pub const fn from_int(value: u8) -> Result<Self, crate::errors::EnumError> {
37        match value {
38            0 => Ok(Self::Banned),
39            1 => Ok(Self::Enabled),
40            2 => Ok(Self::Blizzard),
41            v => Err(crate::errors::EnumError::new(NAME, v as i128),)
42        }
43    }
44}
45
46#[cfg(feature = "print-testcase")]
47impl AddonType {
48    pub const fn as_test_case_value(&self) -> &'static str {
49        match self {
50            Self::Banned => "BANNED",
51            Self::Enabled => "ENABLED",
52            Self::Blizzard => "BLIZZARD",
53        }
54    }
55
56}
57
58const NAME: &str = "AddonType";
59
60impl Default for AddonType {
61    fn default() -> Self {
62        Self::Banned
63    }
64}
65
66impl std::fmt::Display for AddonType {
67    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68        match self {
69            Self::Banned => f.write_str("Banned"),
70            Self::Enabled => f.write_str("Enabled"),
71            Self::Blizzard => f.write_str("Blizzard"),
72        }
73    }
74}
75
76impl TryFrom<u8> for AddonType {
77    type Error = crate::errors::EnumError;
78    fn try_from(value: u8) -> Result<Self, Self::Error> {
79        Self::from_int(value)
80    }
81}
82
83impl TryFrom<u16> for AddonType {
84    type Error = crate::errors::EnumError;
85    fn try_from(value: u16) -> Result<Self, Self::Error> {
86        TryInto::<u8>::try_into(value)
87            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
88            .try_into()
89    }
90}
91
92impl TryFrom<u32> for AddonType {
93    type Error = crate::errors::EnumError;
94    fn try_from(value: u32) -> Result<Self, Self::Error> {
95        TryInto::<u8>::try_into(value)
96            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
97            .try_into()
98    }
99}
100
101impl TryFrom<u64> for AddonType {
102    type Error = crate::errors::EnumError;
103    fn try_from(value: u64) -> Result<Self, Self::Error> {
104        TryInto::<u8>::try_into(value)
105            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
106            .try_into()
107    }
108}
109
110impl TryFrom<i8> for AddonType {
111    type Error = crate::errors::EnumError;
112    fn try_from(value: i8) -> Result<Self, Self::Error> {
113        let v = u8::from_le_bytes(value.to_le_bytes());
114        Self::from_int(v)
115    }
116}
117
118impl TryFrom<i16> for AddonType {
119    type Error = crate::errors::EnumError;
120    fn try_from(value: i16) -> Result<Self, Self::Error> {
121        TryInto::<u8>::try_into(value)
122            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
123            .try_into()
124    }
125}
126
127impl TryFrom<i32> for AddonType {
128    type Error = crate::errors::EnumError;
129    fn try_from(value: i32) -> Result<Self, Self::Error> {
130        TryInto::<u8>::try_into(value)
131            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
132            .try_into()
133    }
134}
135
136impl TryFrom<i64> for AddonType {
137    type Error = crate::errors::EnumError;
138    fn try_from(value: i64) -> Result<Self, Self::Error> {
139        TryInto::<u8>::try_into(value)
140            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
141            .try_into()
142    }
143}
144
145impl TryFrom<usize> for AddonType {
146    type Error = crate::errors::EnumError;
147    fn try_from(value: usize) -> Result<Self, Self::Error> {
148        TryInto::<u8>::try_into(value)
149            .map_err(|_| crate::errors::EnumError::new(NAME, value as i128))?
150            .try_into()
151    }
152}
153