1use serde::{Deserialize, Serialize};
2use std::fmt;
3use std::str::FromStr;
4
5use super::errors;
6
7#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)]
48#[serde(rename_all = "camelCase")]
49pub enum ShdType {
50 Nil,
51 Clear,
52 Solid,
53 HorzStripe,
54 VertStripe,
55 ReverseDiagStripe,
56 DiagStripe,
57 HorzCross,
58 DiagCross,
59 ThinHorzStripe,
60 ThinVertStripe,
61 ThinReverseDiagStripe,
62 ThinDiagStripe,
63 ThinHorzCross,
64 ThinDiagCross,
65 Pct5,
66 Pct10,
67 Pct12,
68 Pct15,
69 Pct20,
70 Pct25,
71 Pct30,
72 Pct35,
73 Pct37,
74 Pct40,
75 Pct45,
76 Pct50,
77 Pct55,
78 Pct60,
79 Pct62,
80 Pct65,
81 Pct70,
82 Pct75,
83 Pct80,
84 Pct85,
85 Pct87,
86 Pct90,
87 Pct95,
88}
89
90impl fmt::Display for ShdType {
91 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
92 match *self {
93 ShdType::Nil => write!(f, "nil"),
94 ShdType::Clear => write!(f, "clear"),
95 ShdType::Solid => write!(f, "solid"),
96 ShdType::HorzStripe => write!(f, "horzStripe"),
97 ShdType::VertStripe => write!(f, "vertStripe"),
98 ShdType::ReverseDiagStripe => write!(f, "reverseDiagStripe"),
99 ShdType::DiagStripe => write!(f, "diagStripe"),
100 ShdType::HorzCross => write!(f, "horzCross"),
101 ShdType::DiagCross => write!(f, "diagCross"),
102 ShdType::ThinHorzStripe => write!(f, "thinHorzStripe"),
103 ShdType::ThinVertStripe => write!(f, "thinVertStripe"),
104 ShdType::ThinReverseDiagStripe => write!(f, "thinReverseDiagStripe"),
105 ShdType::ThinDiagStripe => write!(f, "thinDiagStripe"),
106 ShdType::ThinHorzCross => write!(f, "thinHorzCross"),
107 ShdType::ThinDiagCross => write!(f, "thinDiagCross"),
108 ShdType::Pct5 => write!(f, "pct5"),
109 ShdType::Pct10 => write!(f, "pct10"),
110 ShdType::Pct12 => write!(f, "pct12"),
111 ShdType::Pct15 => write!(f, "pct15"),
112 ShdType::Pct20 => write!(f, "pct20"),
113 ShdType::Pct25 => write!(f, "pct25"),
114 ShdType::Pct30 => write!(f, "pct30"),
115 ShdType::Pct35 => write!(f, "pct35"),
116 ShdType::Pct37 => write!(f, "pct37"),
117 ShdType::Pct40 => write!(f, "pct40"),
118 ShdType::Pct45 => write!(f, "pct45"),
119 ShdType::Pct50 => write!(f, "pct50"),
120 ShdType::Pct55 => write!(f, "pct55"),
121 ShdType::Pct60 => write!(f, "pct60"),
122 ShdType::Pct62 => write!(f, "pct62"),
123 ShdType::Pct65 => write!(f, "pct65"),
124 ShdType::Pct70 => write!(f, "pct70"),
125 ShdType::Pct75 => write!(f, "pct75"),
126 ShdType::Pct80 => write!(f, "pct80"),
127 ShdType::Pct85 => write!(f, "pct85"),
128 ShdType::Pct87 => write!(f, "pct87"),
129 ShdType::Pct90 => write!(f, "pct90"),
130 ShdType::Pct95 => write!(f, "pct95"),
131 }
132 }
133}
134
135impl FromStr for ShdType {
136 type Err = errors::TypeError;
137 fn from_str(s: &str) -> Result<Self, Self::Err> {
138 match s {
139 "nil" => Ok(ShdType::Nil),
140 "clear" => Ok(ShdType::Clear),
141 "solid" => Ok(ShdType::Solid),
142 "horzStripe" => Ok(ShdType::HorzStripe),
143 "vertStripe" => Ok(ShdType::VertStripe),
144 "reverseDiagStripe" => Ok(ShdType::ReverseDiagStripe),
145 "diagStripe" => Ok(ShdType::DiagStripe),
146 "horzCross" => Ok(ShdType::HorzCross),
147 "diagCross" => Ok(ShdType::DiagCross),
148 "thinHorzStripe" => Ok(ShdType::ThinHorzStripe),
149 "thinVertStripe" => Ok(ShdType::ThinVertStripe),
150 "thinReverseDiagStripe" => Ok(ShdType::ThinReverseDiagStripe),
151 "thinDiagStripe" => Ok(ShdType::ThinDiagStripe),
152 "thinHorzCross" => Ok(ShdType::ThinHorzCross),
153 "thinDiagCross" => Ok(ShdType::ThinDiagCross),
154 "pct5" => Ok(ShdType::Pct5),
155 "pct10" => Ok(ShdType::Pct10),
156 "pct12" => Ok(ShdType::Pct12),
157 "pct15" => Ok(ShdType::Pct15),
158 "pct20" => Ok(ShdType::Pct20),
159 "pct25" => Ok(ShdType::Pct25),
160 "pct30" => Ok(ShdType::Pct30),
161 "pct35" => Ok(ShdType::Pct35),
162 "pct37" => Ok(ShdType::Pct37),
163 "pct40" => Ok(ShdType::Pct40),
164 "pct45" => Ok(ShdType::Pct45),
165 "pct50" => Ok(ShdType::Pct50),
166 "pct55" => Ok(ShdType::Pct55),
167 "pct60" => Ok(ShdType::Pct60),
168 "pct62" => Ok(ShdType::Pct62),
169 "pct65" => Ok(ShdType::Pct65),
170 "pct70" => Ok(ShdType::Pct70),
171 "pct75" => Ok(ShdType::Pct75),
172 "pct80" => Ok(ShdType::Pct80),
173 "pct85" => Ok(ShdType::Pct85),
174 "pct87" => Ok(ShdType::Pct87),
175 "pct90" => Ok(ShdType::Pct90),
176 "pct95" => Ok(ShdType::Pct95),
177 _ => Err(errors::TypeError::Unknown),
178 }
179 }
180}