http_type/methods/
impl.rs1use crate::*;
2
3impl Default for Methods {
4 #[inline]
5 fn default() -> Self {
6 Self::UNKNOWN(String::new())
7 }
8}
9
10impl Display for Methods {
11 #[inline]
12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13 let res: &str = match self {
14 Self::GET => GET,
15 Self::POST => POST,
16 Self::CONNECT => CONNECT,
17 Self::DELETE => DELETE,
18 Self::HEAD => HEAD,
19 Self::PATCH => PATCH,
20 Self::TRACE => TRACE,
21 Self::PUT => PUT,
22 Self::OPTIONS => OPTIONS,
23 Self::UNKNOWN(methods) => methods,
24 };
25 write!(f, "{}", res)
26 }
27}
28
29impl FromStr for Methods {
30 type Err = ();
31
32 #[inline]
33 fn from_str(methods_str: &str) -> Result<Self, Self::Err> {
34 match methods_str {
35 methods if methods == GET => Ok(Self::GET),
36 methods if methods == POST => Ok(Self::POST),
37 methods if methods == PUT => Ok(Self::PUT),
38 methods if methods == DELETE => Ok(Self::DELETE),
39 methods if methods == PATCH => Ok(Self::PATCH),
40 methods if methods == HEAD => Ok(Self::HEAD),
41 methods if methods == OPTIONS => Ok(Self::OPTIONS),
42 methods if methods == CONNECT => Ok(Self::CONNECT),
43 methods if methods == TRACE => Ok(Self::TRACE),
44 _ => Ok(Self::UNKNOWN(methods_str.to_string())),
45 }
46 }
47}
48
49impl Methods {
50 #[inline]
54 pub fn new() -> Self {
55 Self::default()
56 }
57
58 #[inline]
62 pub fn is_get(&self) -> bool {
63 matches!(self, Self::GET)
64 }
65
66 #[inline]
70 pub fn is_post(&self) -> bool {
71 matches!(self, Self::POST)
72 }
73
74 #[inline]
78 pub fn is_put(&self) -> bool {
79 matches!(self, Self::PUT)
80 }
81
82 #[inline]
86 pub fn is_delete(&self) -> bool {
87 matches!(self, Self::DELETE)
88 }
89
90 #[inline]
94 pub fn is_patch(&self) -> bool {
95 matches!(self, Self::PATCH)
96 }
97
98 #[inline]
102 pub fn is_head(&self) -> bool {
103 matches!(self, Self::HEAD)
104 }
105
106 #[inline]
110 pub fn is_options(&self) -> bool {
111 matches!(self, Self::OPTIONS)
112 }
113
114 #[inline]
118 pub fn is_connect(&self) -> bool {
119 matches!(self, Self::CONNECT)
120 }
121
122 #[inline]
126 pub fn is_trace(&self) -> bool {
127 matches!(self, Self::TRACE)
128 }
129
130 #[inline]
134 pub fn is_unknown(&self) -> bool {
135 matches!(self, Self::UNKNOWN(_))
136 }
137}