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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use std::vec::Vec;
use std::str::FromStr;
#[derive(Clone, Debug)]
pub struct OptionParseError {
reason: String,
}
#[derive(Clone, Debug, PartialEq)]
pub enum Show {
None,
All,
Incoming,
Outgoing,
}
impl FromStr for Show {
type Err = OptionParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_ref() {
"all" => Ok(Show::All),
"in" => Ok(Show::Incoming),
"out" => Ok(Show::Outgoing),
_ => Err(OptionParseError {
reason: format!("{} is not valid", s),
}),
}
}
}
#[derive(Clone, Debug)]
pub struct Options {
pub silent: bool,
pub url: String,
pub show_control_frames: Show,
pub echo: bool,
pub print_headers: bool,
pub headers: Vec<String>,
}
impl Default for Options {
fn default() -> Options {
Options {
url: String::new(),
show_control_frames: Show::None,
echo: false,
silent: false,
print_headers: false,
headers: Vec::new(),
}
}
}
impl Options {
pub fn nothing() -> Options {
Options {
url: String::new(),
show_control_frames: Show::None,
echo: false,
silent: false,
print_headers: false,
headers: Vec::new(),
}
}
}