use crate::*;
impl Default for Method {
#[inline(always)]
fn default() -> Self {
Self::Unknown(String::new())
}
}
impl Display for Method {
#[inline(always)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let res: &str = match self {
Self::Get => GET,
Self::Post => POST,
Self::Connect => CONNECT,
Self::Delete => DELETE,
Self::Head => HEAD,
Self::Patch => PATCH,
Self::Trace => TRACE,
Self::Put => PUT,
Self::Options => OPTIONS,
Self::Unknown(methods) => methods,
};
write!(f, "{res}")
}
}
impl FromStr for Method {
type Err = ();
#[inline(always)]
fn from_str(methods_str: &str) -> Result<Self, Self::Err> {
match methods_str {
GET => Ok(Self::Get),
POST => Ok(Self::Post),
PUT => Ok(Self::Put),
DELETE => Ok(Self::Delete),
PATCH => Ok(Self::Patch),
HEAD => Ok(Self::Head),
OPTIONS => Ok(Self::Options),
CONNECT => Ok(Self::Connect),
TRACE => Ok(Self::Trace),
_ => Ok(Self::Unknown(methods_str.to_string())),
}
}
}
impl Method {
#[inline(always)]
pub fn is_get(&self) -> bool {
matches!(self, Self::Get)
}
#[inline(always)]
pub fn is_post(&self) -> bool {
matches!(self, Self::Post)
}
#[inline(always)]
pub fn is_put(&self) -> bool {
matches!(self, Self::Put)
}
#[inline(always)]
pub fn is_delete(&self) -> bool {
matches!(self, Self::Delete)
}
#[inline(always)]
pub fn is_patch(&self) -> bool {
matches!(self, Self::Patch)
}
#[inline(always)]
pub fn is_head(&self) -> bool {
matches!(self, Self::Head)
}
#[inline(always)]
pub fn is_options(&self) -> bool {
matches!(self, Self::Options)
}
#[inline(always)]
pub fn is_connect(&self) -> bool {
matches!(self, Self::Connect)
}
#[inline(always)]
pub fn is_trace(&self) -> bool {
matches!(self, Self::Trace)
}
#[inline(always)]
pub fn is_unknown(&self) -> bool {
matches!(self, Self::Unknown(_))
}
}