1use std::str::FromStr;
2
3#[derive(Debug, PartialEq, Eq)]
5pub enum HttpMethod {
6 GET,
7 HEAD
8}
9
10impl FromStr for HttpMethod {
11 type Err = &'static str;
12
13 fn from_str(s: &str) -> Result<Self, Self::Err> {
15 match s {
16 "GET" => Ok(HttpMethod::GET),
17 "HEAD" => Ok(HttpMethod::HEAD),
18 _ => Err("HTTP method not supported."),
19 }
20 }
21}
22
23#[derive(Debug, PartialEq, Eq)]
25pub enum HttpVersion {
26 Http1_0,
27 Http1_1,
28}
29
30impl FromStr for HttpVersion {
31 type Err = &'static str;
32
33 fn from_str(s: &str) -> Result<Self, Self::Err> {
35 match s {
36 "HTTP/1.0" => Ok(HttpVersion::Http1_0),
37 "HTTP/1.1" => Ok(HttpVersion::Http1_1),
38 _ => Err("Unsupported HTTP version"),
39 }
40 }
41}