#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Method {
Get,
Post,
Put,
Delete,
Patch,
Head,
Options,
Trace,
Connect,
Unknown(String),
}
impl std::fmt::Display for Method {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Method::Get => f.write_str("GET"),
Method::Post => f.write_str("POST"),
Method::Put => f.write_str("PUT"),
Method::Delete => f.write_str("DELETE"),
Method::Patch => f.write_str("PATCH"),
Method::Head => f.write_str("HEAD"),
Method::Options => f.write_str("OPTIONS"),
Method::Trace => f.write_str("TRACE"),
Method::Connect => f.write_str("CONNECT"),
Method::Unknown(other) => f.write_str(other),
}
}
}
impl From<&str> for Method {
fn from(s: &str) -> Self {
match s {
"GET" => Method::Get,
"POST" => Method::Post,
"PUT" => Method::Put,
"DELETE" => Method::Delete,
"PATCH" => Method::Patch,
"HEAD" => Method::Head,
"OPTIONS" => Method::Options,
"TRACE" => Method::Trace,
"CONNECT" => Method::Connect,
other => Method::Unknown(other.to_string()),
}
}
}