1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#[macro_export] macro_rules! route { ($(#[$meta:meta])* $func_name:ident) => ( $(#[$meta])* pub fn $func_name<H>(&mut self, pattern: &str, handle: H) -> &mut Route where H: Fn(&mut Context) + Send + Sync + 'static { self.add(stringify!($func_name).to_uppercase().parse().unwrap(), pattern, handle) } ) } #[macro_export] macro_rules! middleware { ($(#[$meta:meta])* $func_name:ident) => ( $(#[$meta])* pub fn $func_name<H>(&mut self, handle: H) -> &mut Self where H: Fn(&mut Context) + Send + Sync + 'static { self.$func_name.push(Middleware { inner: Box::new(handle), }); self } ) }