mini_async_http/http/
method.rs1use std::str::FromStr;
2
3#[derive(Debug, PartialEq)]
4pub enum Method {
5 GET,
6 POST,
7 PUT,
8 DELETE,
9}
10
11impl Method {
12 pub fn as_str(&self) -> &str {
13 match self {
14 Method::GET => "GET",
15 Method::POST => "POST",
16 Method::PUT => "PUT",
17 Method::DELETE => "DELETE",
18 }
19 }
20}
21
22impl FromStr for Method {
23 type Err = ();
24
25 fn from_str(s: &str) -> Result<Self, Self::Err> {
26 match s {
27 "GET" => Ok(Method::GET),
28 "POST" => Ok(Method::POST),
29 "DELETE" => Ok(Method::DELETE),
30 "PUT" => Ok(Method::PUT),
31 _ => Err(()),
32 }
33 }
34}
35
36#[cfg(test)]
37mod test {
38 use super::*;
39
40 #[test]
41 fn as_str() {
42 assert_eq!(Method::GET.as_str(), "GET");
43 assert_eq!(Method::PUT.as_str(), "PUT");
44 assert_eq!(Method::DELETE.as_str(), "DELETE");
45 assert_eq!(Method::POST.as_str(), "POST");
46 }
47}