use crate::utils::BoxCloneService;
#[cfg(feature = "types")]
pub use crate::types::*;
macro_rules! impl_method {
($( $method_name:ident $method:ident ),*) => {
$(
pub fn $method_name<H, Args>(handler: H) -> $crate::endpoint::Endpoint
where
H: titan_core::Handler<Args> + Sync + Clone,
H::Future: std::future::Future<Output = H::Output> + Send,
H::Output: titan_core::Respondable,
Args: titan_core::FromRequest + Send + Sync + 'static,
Args::Error: Send
{
let mut methods = std::collections::HashMap::default();
let route = $crate::route::Route::new(handler);
methods.insert(titan_http::Method::$method, BoxCloneService::new(route));
$crate::endpoint::Endpoint { methods }
}
)*
};
}
pub fn any<H, Args>(handler: H) -> crate::endpoint::Endpoint
where
H: titan_core::Handler<Args> + Sync + Clone,
H::Future: std::future::Future<Output = H::Output> + Send,
H::Output: titan_core::Respondable,
Args: titan_core::FromRequest + Send + Sync + 'static,
Args::Error: Send,
{
let mut methods = std::collections::HashMap::default();
let route = crate::route::Route::new(handler);
methods.insert(titan_http::Method::GET, BoxCloneService::new(route.clone()));
methods.insert(titan_http::Method::POST, BoxCloneService::new(route.clone()));
methods.insert(titan_http::Method::PUT, BoxCloneService::new(route.clone()));
methods
.insert(titan_http::Method::DELETE, BoxCloneService::new(route.clone()));
methods.insert(titan_http::Method::PATCH, BoxCloneService::new(route));
crate::endpoint::Endpoint { methods }
}
impl_method!(get GET, post POST, put PUT, delete DELETE, patch PATCH);