#![forbid(unsafe_code)]
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Method {
Get,
Post,
Put,
Delete,
Patch,
Options,
Head,
Trace,
}
impl Method {
#[must_use]
pub fn from_bytes(bytes: &[u8]) -> Option<Self> {
match bytes {
b"GET" => Some(Self::Get),
b"POST" => Some(Self::Post),
b"PUT" => Some(Self::Put),
b"DELETE" => Some(Self::Delete),
b"PATCH" => Some(Self::Patch),
b"OPTIONS" => Some(Self::Options),
b"HEAD" => Some(Self::Head),
b"TRACE" => Some(Self::Trace),
_ => None,
}
}
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Get => "GET",
Self::Post => "POST",
Self::Put => "PUT",
Self::Delete => "DELETE",
Self::Patch => "PATCH",
Self::Options => "OPTIONS",
Self::Head => "HEAD",
Self::Trace => "TRACE",
}
}
}
impl fmt::Display for Method {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}