use std::{collections::HashMap, future::Future, net::SocketAddr, pin::Pin}; use either::Either; use hyper::{Body, Method, Response}; use regex::Regex; use crate::{Request, routing::Router}; #[derive(Clone)] pub struct Route { pub handler: fn(Request, Option, B) -> Pin> + Send >>, pub middleware: Option, B) -> Pin, B), Response> > + Send >> >>, } #[derive(Clone)] pub struct RegexPath { pub regex: Regex, pub routes: HashMap>, } #[derive(Clone)] pub struct MarlaConfig { pub routers: Vec>>, pub middleware: Vec< fn(Request, Option, B) -> Pin, B), Response> > + Send >> >, pub listen_addr: SocketAddr, } #[macro_export] macro_rules! async_handler {( $( #[$attr:meta] )* // includes doc strings $pub:vis async fn $fname:ident ( $($args:tt)* ) $(-> $Ret:ty)? { $($body:tt)* } ) => ( $( #[$attr] )* #[allow(unused_parens)] $pub fn $fname ( $($args)* ) -> ::std::pin::Pin<::std::boxed::Box< dyn ::std::future::Future + ::std::marker::Send >> { ::std::boxed::Box::pin(async move { $($body)* }) } )} #[macro_export] macro_rules! async_router {( $( #[$attr:meta] )* // includes doc strings $pub:vis async fn $fname:ident ( $($args:tt)* ) $(-> $Ret:ty)? { $($body:tt)* } ) => ( $( #[$attr] )* #[allow(unused_parens)] $pub fn $fname ( $($args)* ) -> ::std::pin::Pin<::std::boxed::Box< dyn ::std::future::Future + ::std::marker::Send + '_ >> { ::std::boxed::Box::pin(async move { $($body)* }) } )}