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
#[derive(Debug, Clone, PartialEq, Hash, Eq)]
pub enum Method {
Head = 0,
Get,
Post,
Put,
Patch,
Delete,
Options,
Connect,
Trace,
}
impl Method {
pub fn all() -> Vec<Method> {
vec![
Method::Head,
Method::Get,
Method::Post,
Method::Put,
Method::Patch,
Method::Delete,
Method::Options,
Method::Connect,
Method::Trace,
]
}
}
impl From<String> for Method {
fn from(m: String) -> Self {
match m.to_ascii_uppercase().as_str() {
"HEAD" => Method::Head,
"POST" => Method::Post,
"PUT" => Method::Put,
"PATCH" => Method::Patch,
"DELETE" => Method::Delete,
"OPTIONS" => Method::Options,
"CONNECT" => Method::Connect,
"TRACE" => Method::Trace,
_ => Method::Get,
}
}
}
impl From<Method> for String {
fn from(val: Method) -> Self {
match val {
Method::Head => "HEAD",
Method::Post => "POST",
Method::Put => "PUT",
Method::Patch => "PATCH",
Method::Delete => "DELETE",
Method::Options => "OPTIONS",
Method::Connect => "CONNECT",
Method::Trace => "TRACE",
Method::Get => "GET",
}
.to_string()
}
}
impl ToString for Method {
fn to_string(&self) -> String {
(*self).clone().into()
}
}
impl Default for Method {
fn default() -> Self {
Method::Get
}
}