wow_world_base/inner/vanilla/
dismount_result.rs1#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Copy, Clone)]
9#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
10pub enum DismountResult {
11 NotMounted,
12 Ok,
13}
14
15impl DismountResult {
16 pub const fn as_int(&self) -> u32 {
17 match self {
18 Self::NotMounted => 0x1,
19 Self::Ok => 0x3,
20 }
21 }
22
23 pub const fn variants() -> [Self; 2] {
24 [
25 Self::NotMounted,
26 Self::Ok,
27 ]
28 }
29
30 pub const fn from_int(value: u32) -> Result<Self, crate::errors::EnumError> {
31 match value {
32 1 => Ok(Self::NotMounted),
33 3 => Ok(Self::Ok),
34 v => Err(crate::errors::EnumError::new(NAME, v as i128),)
35 }
36 }
37}
38
39#[cfg(feature = "print-testcase")]
40impl DismountResult {
41 pub const fn as_test_case_value(&self) -> &'static str {
42 match self {
43 Self::NotMounted => "NOT_MOUNTED",
44 Self::Ok => "OK",
45 }
46 }
47
48}
49
50const NAME: &str = "DismountResult";
51
52impl Default for DismountResult {
53 fn default() -> Self {
54 Self::NotMounted
55 }
56}
57
58impl std::fmt::Display for DismountResult {
59 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60 match self {
61 Self::NotMounted => f.write_str("NotMounted"),
62 Self::Ok => f.write_str("Ok"),
63 }
64 }
65}
66
67impl TryFrom<u32> for DismountResult {
68 type Error = crate::errors::EnumError;
69 fn try_from(value: u32) -> Result<Self, Self::Error> {
70 Self::from_int(value)
71 }
72}
73
74impl TryFrom<u8> for DismountResult {
75 type Error = crate::errors::EnumError;
76 fn try_from(value: u8) -> Result<Self, Self::Error> {
77 Self::from_int(value.into())
78 }
79}
80
81impl TryFrom<u16> for DismountResult {
82 type Error = crate::errors::EnumError;
83 fn try_from(value: u16) -> Result<Self, Self::Error> {
84 Self::from_int(value.into())
85 }
86}
87
88impl TryFrom<u64> for DismountResult {
89 type Error = crate::errors::EnumError;
90 fn try_from(value: u64) -> Result<Self, Self::Error> {
91 TryInto::<u32>::try_into(value)
92 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
93 .try_into()
94 }
95}
96
97impl TryFrom<i8> for DismountResult {
98 type Error = crate::errors::EnumError;
99 fn try_from(value: i8) -> Result<Self, Self::Error> {
100 TryInto::<u32>::try_into(value)
101 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
102 .try_into()
103 }
104}
105
106impl TryFrom<i16> for DismountResult {
107 type Error = crate::errors::EnumError;
108 fn try_from(value: i16) -> Result<Self, Self::Error> {
109 TryInto::<u32>::try_into(value)
110 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
111 .try_into()
112 }
113}
114
115impl TryFrom<i32> for DismountResult {
116 type Error = crate::errors::EnumError;
117 fn try_from(value: i32) -> Result<Self, Self::Error> {
118 let v = u32::from_le_bytes(value.to_le_bytes());
119 Self::from_int(v)
120 }
121}
122
123impl TryFrom<i64> for DismountResult {
124 type Error = crate::errors::EnumError;
125 fn try_from(value: i64) -> Result<Self, Self::Error> {
126 TryInto::<u32>::try_into(value)
127 .map_err(|_| crate::errors::EnumError::new(NAME, value.into()))?
128 .try_into()
129 }
130}
131
132impl TryFrom<usize> for DismountResult {
133 type Error = crate::errors::EnumError;
134 fn try_from(value: usize) -> Result<Self, Self::Error> {
135 TryInto::<u32>::try_into(value)
136 .map_err(|_| crate::errors::EnumError::new(NAME, value as i128))?
137 .try_into()
138 }
139}
140