pillow_http/
http_methods.rs1#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
7pub enum HttpMethods {
8 GET,
9 POST,
10 PUT,
11 DELETE,
12 HEAD,
13 OPTIONS,
14 CONNECT,
15 PATCH,
16 TRACE,
17}
18
19impl HttpMethods {
20 pub fn as_str(&self) -> &'static str {
27 match self {
28 HttpMethods::GET => "GET",
29 HttpMethods::POST => "POST",
30 HttpMethods::PUT => "PUT",
31 HttpMethods::DELETE => "DELETE",
32
33 HttpMethods::HEAD => "HEAD",
34 HttpMethods::OPTIONS => "OPTIONS",
35 HttpMethods::CONNECT => "CONNECT",
36 HttpMethods::PATCH => "PATCH",
37 HttpMethods::TRACE => "TRACE",
38 }
39 }
40}
41
42pub fn from_str_to_http_method(s: &str) -> Result<HttpMethods, ()> {
49 match s {
50 "GET" => Ok(HttpMethods::GET),
51 "POST" => Ok(HttpMethods::POST),
52 "PUT" => Ok(HttpMethods::PUT),
53 "DELETE" => Ok(HttpMethods::DELETE),
54
55 "HEAD" => Ok(HttpMethods::HEAD),
56 "OPTIONS" => Ok(HttpMethods::OPTIONS),
57 "CONNECT" => Ok(HttpMethods::CONNECT),
58 "PATCH" => Ok(HttpMethods::PATCH),
59 "TRACE" => Ok(HttpMethods::TRACE),
60
61 _ => Err(()),
62 }
63}