use std::fmt::Display; #[cfg(feature = "http")] pub mod body; #[cfg(feature = "http")] mod header; #[cfg(feature = "http")] mod redirect; #[cfg(feature = "http")] pub mod request; #[cfg(feature = "http")] pub mod response; /// A [`Method`](https://developer.mozilla.org/en-US/docs/Web/API/Request/method) representation /// used on Request objects. #[derive(Default, Debug, Clone, PartialEq, Hash, Eq)] pub enum Method { Head = 0, #[default] Get, Post, Put, Patch, Delete, Options, Connect, Trace, Report, } impl Method { pub fn all() -> Vec { vec![ Method::Head, Method::Get, Method::Post, Method::Put, Method::Patch, Method::Delete, Method::Options, Method::Connect, Method::Trace, Method::Report, ] } } impl From for Method { fn from(m: String) -> Self { match m.to_ascii_uppercase().as_str() { "HEAD" => Method::Head, "POST" => Method::Post, "PUT" => Method::Put, "PATCH" => Method::Patch, "DELETE" => Method::Delete, "OPTIONS" => Method::Options, "CONNECT" => Method::Connect, "TRACE" => Method::Trace, "REPORT" => Method::Report, _ => Method::Get, } } } impl From for String { fn from(val: Method) -> Self { val.as_ref().to_string() } } impl AsRef for Method { fn as_ref(&self) -> &'static str { match self { Method::Head => "HEAD", Method::Post => "POST", Method::Put => "PUT", Method::Patch => "PATCH", Method::Delete => "DELETE", Method::Options => "OPTIONS", Method::Connect => "CONNECT", Method::Trace => "TRACE", Method::Get => "GET", Method::Report => "REPORT", } } } impl Display for Method { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { let s: String = (*self).clone().into(); write!(f, "{s}") } }