1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::fmt;
use std::str::FromStr;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Style {
Expanded,
Compressed,
Introspection,
}
impl fmt::Display for Style {
fn fmt(&self, out: &mut fmt::Formatter) -> Result<(), fmt::Error> {
out.write_str(match self {
Style::Compressed => "compressed",
Style::Expanded => "expanded",
Style::Introspection => "introspection",
})
}
}
impl FromStr for Style {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_ascii_lowercase().as_ref() {
"compressed" => Ok(Style::Compressed),
"expanded" => Ok(Style::Expanded),
s => Err(format!("Output style {:?} not supported", s)),
}
}
}
static FORMAT_NAMES: [&str; 2] = ["Compressed", "Expanded"];
impl Style {
pub fn variants() -> &'static [&'static str] {
&FORMAT_NAMES
}
}