use crate::Error;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Method {
Get,
Post,
Put,
Patch,
Delete,
Head,
Options,
}
impl Method {
pub(crate) const fn as_bytes(self) -> &'static [u8] {
match self {
Self::Get => b"GET",
Self::Post => b"POST",
Self::Put => b"PUT",
Self::Patch => b"PATCH",
Self::Delete => b"DELETE",
Self::Head => b"HEAD",
Self::Options => b"OPTIONS",
}
}
pub(crate) fn from_bytes(value: &[u8]) -> Result<Self, Error> {
match value {
b"GET" => Ok(Self::Get),
b"POST" => Ok(Self::Post),
b"PUT" => Ok(Self::Put),
b"PATCH" => Ok(Self::Patch),
b"DELETE" => Ok(Self::Delete),
b"HEAD" => Ok(Self::Head),
b"OPTIONS" => Ok(Self::Options),
_ => Err(Error::UnsupportedMethod),
}
}
}