wow_world_base/inner/tbc/
expansion.rs

1/// Auto generated from the original `wowm` in file [`wow_message_parser/wowm/world/character_screen/smsg_auth_response.wowm:59`](https://github.com/gtker/wow_messages/tree/main/wow_message_parser/wowm/world/character_screen/smsg_auth_response.wowm#L59):
2/// ```text
3/// enum Expansion : u8 {
4///     VANILLA = 0;
5///     THE_BURNING_CRUSADE = 1;
6/// }
7/// ```
8#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Copy, Clone)]
9#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
10pub enum Expansion {
11    Vanilla,
12    TheBurningCrusade,
13}
14
15impl Expansion {
16    pub const fn as_int(&self) -> u8 {
17        match self {
18            Self::Vanilla => 0x0,
19            Self::TheBurningCrusade => 0x1,
20        }
21    }
22
23    pub const fn variants() -> [Self; 2] {
24        [
25            Self::Vanilla,
26            Self::TheBurningCrusade,
27        ]
28    }
29
30    pub const fn from_int(value: u8) -> Result<Self, crate::errors::EnumError> {
31        match value {
32            0 => Ok(Self::Vanilla),
33            1 => Ok(Self::TheBurningCrusade),
34            v => Err(crate::errors::EnumError::new(NAME, v as i128),)
35        }
36    }
37}
38
39#[cfg(feature = "print-testcase")]
40impl Expansion {
41    pub const fn as_test_case_value(&self) -> &'static str {
42        match self {
43            Self::Vanilla => "VANILLA",
44            Self::TheBurningCrusade => "THE_BURNING_CRUSADE",
45        }
46    }
47
48}
49
50const NAME: &str = "Expansion";
51
52impl Default for Expansion {
53    fn default() -> Self {
54        Self::Vanilla
55    }
56}
57
58impl std::fmt::Display for Expansion {
59    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60        match self {
61            Self::Vanilla => f.write_str("Vanilla"),
62            Self::TheBurningCrusade => f.write_str("TheBurningCrusade"),
63        }
64    }
65}
66
67impl TryFrom<u8> for Expansion {
68    type Error = crate::errors::EnumError;
69    fn try_from(value: u8) -> Result<Self, Self::Error> {
70        Self::from_int(value)
71    }
72}
73
74impl TryFrom<u16> for Expansion {
75    type Error = crate::errors::EnumError;
76    fn try_from(value: u16) -> Result<Self, Self::Error> {
77        TryInto::<u8>::try_into(value)
78            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
79            .try_into()
80    }
81}
82
83impl TryFrom<u32> for Expansion {
84    type Error = crate::errors::EnumError;
85    fn try_from(value: u32) -> 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<u64> for Expansion {
93    type Error = crate::errors::EnumError;
94    fn try_from(value: u64) -> 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<i8> for Expansion {
102    type Error = crate::errors::EnumError;
103    fn try_from(value: i8) -> Result<Self, Self::Error> {
104        let v = u8::from_le_bytes(value.to_le_bytes());
105        Self::from_int(v)
106    }
107}
108
109impl TryFrom<i16> for Expansion {
110    type Error = crate::errors::EnumError;
111    fn try_from(value: i16) -> Result<Self, Self::Error> {
112        TryInto::<u8>::try_into(value)
113            .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
114            .try_into()
115    }
116}
117
118impl TryFrom<i32> for Expansion {
119    type Error = crate::errors::EnumError;
120    fn try_from(value: i32) -> 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<i64> for Expansion {
128    type Error = crate::errors::EnumError;
129    fn try_from(value: i64) -> 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<usize> for Expansion {
137    type Error = crate::errors::EnumError;
138    fn try_from(value: usize) -> Result<Self, Self::Error> {
139        TryInto::<u8>::try_into(value)
140            .map_err(|_| crate::errors::EnumError::new(NAME, value as i128))?
141            .try_into()
142    }
143}
144