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
#[derive(Debug)]
/// Storing http methods and path
pub struct HttpRoute {
    pub method: HttpMethod,
    pub route: String,
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[allow(dead_code)]
/// Represents http's methods
pub enum HttpMethod {
    GET,
    HEAD,
    POST,
    PUT,
    DELETE,
    TRACE,
    OPTIONS,
    Any,
}

impl std::str::FromStr for HttpMethod {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "GET" => Ok(HttpMethod::GET),
            "HEAD" => Ok(HttpMethod::HEAD),
            "POST" => Ok(HttpMethod::POST),
            "PUT" => Ok(HttpMethod::PUT),
            "DELETE" => Ok(HttpMethod::DELETE),
            "TRACE" => Ok(HttpMethod::TRACE),
            "OPTIONS" => Ok(HttpMethod::OPTIONS),
            _ => Err(()),
        }
    }
}