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