noxp/http/
method.rs

1/// The method type to handle HTTP method
2#[derive(Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
3pub enum Method {
4    GET,
5    POST,
6    PUT,
7    DELETE,
8    HEAD,
9    CONNECT,
10    OPTIONS,
11    TRACE,
12    PATCH
13}
14
15impl Method {
16    /// Convert a `&str` to a `Method`
17    pub fn from_str(s: &str) -> Self {
18        match s {
19            "GET" => Self::GET,
20            "POST" => Self::POST,
21            "PUT" => Self::PUT,
22            "DELETE" => Self::DELETE,
23            "HEAD" => Self::HEAD,
24            "CONNECT" => Self::CONNECT,
25            "OPTIONS" => Self::OPTIONS,
26            "TRACE" => Self::TRACE,
27            "PATCH" => Self::PATCH,
28            _ => panic!("If you're seeing this, congratulations!\nYou somehow created a new HTTP method!"),
29        }
30    }
31
32    /// Convert a `Method` into a `&str`
33    pub fn to_str(&self) -> &str {
34        match self {
35            Method::GET => "GET",
36            Method::POST => "POST",
37            Method::PUT => "PUT",
38            Method::DELETE => "DELETE",
39            Method::HEAD => "HEAD",
40            Method::CONNECT => "CONNECT",
41            Method::OPTIONS => "OPTIONS",
42            Method::TRACE => "TRACE",
43            Method::PATCH => "PATCH",
44        }
45    }
46}