wow_world_base/inner/wrath/
item_text_query.rs

1/// Auto generated from the original `wowm` in file [`wow_message_parser/wowm/world/queries/smsg_item_text_query_response.wowm:9`](https://github.com/gtker/wow_messages/tree/main/wow_message_parser/wowm/world/queries/smsg_item_text_query_response.wowm#L9):
2/// ```text
3/// enum ItemTextQuery : u8 {
4///     HAS_TEXT = 0;
5///     NO_TEXT = 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 ItemTextQuery {
11    HasText,
12    NoText,
13}
14
15impl ItemTextQuery {
16    pub const fn as_int(&self) -> u8 {
17        match self {
18            Self::HasText => 0x0,
19            Self::NoText => 0x1,
20        }
21    }
22
23    pub const fn variants() -> [Self; 2] {
24        [
25            Self::HasText,
26            Self::NoText,
27        ]
28    }
29
30    pub const fn from_int(value: u8) -> Result<Self, crate::errors::EnumError> {
31        match value {
32            0 => Ok(Self::HasText),
33            1 => Ok(Self::NoText),
34            v => Err(crate::errors::EnumError::new(NAME, v as i128),)
35        }
36    }
37}
38
39#[cfg(feature = "print-testcase")]
40impl ItemTextQuery {
41    pub const fn as_test_case_value(&self) -> &'static str {
42        match self {
43            Self::HasText => "HAS_TEXT",
44            Self::NoText => "NO_TEXT",
45        }
46    }
47
48}
49
50const NAME: &str = "ItemTextQuery";
51
52impl Default for ItemTextQuery {
53    fn default() -> Self {
54        Self::HasText
55    }
56}
57
58impl std::fmt::Display for ItemTextQuery {
59    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60        match self {
61            Self::HasText => f.write_str("HasText"),
62            Self::NoText => f.write_str("NoText"),
63        }
64    }
65}
66
67impl TryFrom<u8> for ItemTextQuery {
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 ItemTextQuery {
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 ItemTextQuery {
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 ItemTextQuery {
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 ItemTextQuery {
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 ItemTextQuery {
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 ItemTextQuery {
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 ItemTextQuery {
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 ItemTextQuery {
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