use std::fmt;
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub enum HttpMethod {
Get,
Post,
Put,
Delete,
Head,
Options,
Patch,
Trace,
}
impl fmt::Display for HttpMethod {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
HttpMethod::Get => "GET",
HttpMethod::Post => "POST",
HttpMethod::Put => "PUT",
HttpMethod::Delete => "DELETE",
HttpMethod::Head => "HEAD",
HttpMethod::Options => "OPTIONS",
HttpMethod::Patch => "PATCH",
HttpMethod::Trace => "TRACE",
})
}
}
impl HttpMethod {
#[cfg(feature = "actix")]
pub fn actix(&self) -> actix_web::http::Method {
use actix_web::http::Method as Actix;
match self {
HttpMethod::Get => Actix::GET,
HttpMethod::Post => Actix::POST,
HttpMethod::Put => Actix::PUT,
HttpMethod::Delete => Actix::DELETE,
HttpMethod::Head => Actix::HEAD,
HttpMethod::Options => Actix::OPTIONS,
HttpMethod::Patch => Actix::PATCH,
HttpMethod::Trace => Actix::TRACE,
}
}
#[cfg(feature = "axum")]
pub fn axum(&self) -> axum::routing::MethodFilter {
use axum::routing::MethodFilter as Axum;
match self {
HttpMethod::Get => Axum::GET,
HttpMethod::Post => Axum::POST,
HttpMethod::Put => Axum::PUT,
HttpMethod::Delete => Axum::DELETE,
HttpMethod::Head => Axum::HEAD,
HttpMethod::Options => Axum::OPTIONS,
HttpMethod::Patch => Axum::PATCH,
HttpMethod::Trace => Axum::TRACE,
}
}
}