use std::fmt;
use std::str::FromStr;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Method {
Connect,
Delete,
Get,
Head,
Options,
Patch,
Post,
Put,
Trace,
Copy,
Lock,
Mkcol,
Move,
Propfind,
Proppatch,
Unlock,
Mkcalendar, Report, Search, Purge, }
impl Method {
pub fn as_str(self) -> &'static str {
match self {
Self::Connect => "CONNECT",
Self::Copy => "COPY",
Self::Delete => "DELETE",
Self::Get => "GET",
Self::Head => "HEAD",
Self::Lock => "LOCK",
Self::Mkcalendar => "MKCALENDAR",
Self::Mkcol => "MKCOL",
Self::Move => "MOVE",
Self::Options => "OPTIONS",
Self::Patch => "PATCH",
Self::Post => "POST",
Self::Propfind => "PROPFIND",
Self::Proppatch => "PROPPATCH",
Self::Purge => "PURGE",
Self::Put => "PUT",
Self::Report => "REPORT",
Self::Search => "SEARCH",
Self::Trace => "TRACE",
Self::Unlock => "UNLOCK",
}
}
}
impl FromStr for Method {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"CONNECT" => Ok(Self::Connect),
"COPY" => Ok(Self::Copy),
"DELETE" => Ok(Self::Delete),
"GET" => Ok(Self::Get),
"HEAD" => Ok(Self::Head),
"LOCK" => Ok(Self::Lock),
"MKCALENDAR" => Ok(Self::Mkcalendar),
"MKCOL" => Ok(Self::Mkcol),
"MOVE" => Ok(Self::Move),
"OPTIONS" => Ok(Self::Options),
"PATCH" => Ok(Self::Patch),
"POST" => Ok(Self::Post),
"PROPFIND" => Ok(Self::Propfind),
"PROPPATCH" => Ok(Self::Proppatch),
"PURGE" => Ok(Self::Purge),
"PUT" => Ok(Self::Put),
"REPORT" => Ok(Self::Report),
"SEARCH" => Ok(Self::Search),
"TRACE" => Ok(Self::Trace),
"UNLOCK" => Ok(Self::Unlock),
_ => Err(()),
}
}
}
impl fmt::Display for Method {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}