🏗️ Elegant & Highly Performant Async Gemini Server Framework for the Modern Age
async framework gemini-protocol protocol gemini rust
at main 118 lines 3.1 kB view raw
1macro_rules! sync_response { 2 ($($name:ident),*) => { 3 $( 4 /// Trailing commas are not supported at the moment! 5 #[macro_export] 6 macro_rules! $name { 7 ($body:expr /* $(,)? */) => { 8 |_: $crate::context::RouteContext| $crate::response::Response::$name($body) 9 }; 10 ($context:ident, $body:expr /* $(,)? */) => { 11 |$context: $crate::context::RouteContext| $crate::response::Response::$name($body) 12 }; 13 } 14 )* 15 }; 16} 17 18macro_rules! async_response { 19 ($($name:ident),*) => { 20 $(::paste::paste! { 21 /// Trailing commas are not supported at the moment! 22 #[macro_export] 23 macro_rules! [< $name _async >] { 24 ($body:expr /* $(,)? */) => { 25 |_: $crate::context::RouteContext| async { $crate::response::Response::$name($body) } 26 }; 27 ($context:ident, $body:expr /* $(,)? */) => { 28 |$context: $crate::context::RouteContext| async { $crate::response::Response::$name($body) } 29 }; 30 } 31 })* 32 }; 33} 34 35macro_rules! response { 36 ($($name:ident),* $(,)?) => { 37 $( 38 sync_response!($name); 39 async_response!($name); 40 )* 41 }; 42} 43 44response!( 45 input, 46 sensitive_input, 47 success, 48 temporary_redirect, 49 permanent_redirect, 50 temporary_failure, 51 server_unavailable, 52 cgi_error, 53 proxy_error, 54 slow_down, 55 permanent_failure, 56 not_found, 57 gone, 58 proxy_refused, 59 bad_request, 60 client_certificate_required, 61 certificate_not_valid, 62); 63 64#[cfg(feature = "auto-deduce-mime")] 65response!(binary_success_auto); 66 67/// Trailing commas are not supported at the moment! 68#[macro_export] 69macro_rules! binary_success { 70 ($body:expr, $mime:expr) => { 71 |_: $crate::context::RouteContext| { 72 $crate::response::Response::binary_success($body, $mime) 73 } 74 }; 75 ($body:expr) => {{ 76 #[cfg(not(feature = "auto-deduce-mime"))] 77 compile_error!( 78 "`binary_success` without a MIME type requires the `auto-deduce-mime` \ 79 feature to be enabled" 80 ); 81 82 |_: $crate::context::RouteContext| { 83 #[cfg(feature = "auto-deduce-mime")] 84 return $crate::response::Response::binary_success_auto($body); 85 86 // Suppress item not found warning 87 #[cfg(not(feature = "auto-deduce-mime"))] 88 $crate::response::Response::binary_success( 89 $body, 90 "application/octet-stream", 91 ) 92 } 93 }}; 94 ($context:ident, $body:expr, $mime:expr) => { 95 |$context: $crate::context::RouteContext| { 96 $crate::response::Response::binary_success($body, $mime) 97 } 98 }; 99 ($context:ident, $body:expr) => {{ 100 #[cfg(not(feature = "auto-deduce-mime"))] 101 compile_error!( 102 "`binary_success` without a MIME type requires the `auto-deduce-mime` \ 103 feature to be enabled" 104 ); 105 106 |$context: $crate::context::RouteContext| { 107 #[cfg(feature = "auto-deduce-mime")] 108 return $crate::response::Response::binary_success_auto($body); 109 110 // Suppress item not found warning 111 #[cfg(not(feature = "auto-deduce-mime"))] 112 $crate::response::Response::binary_success( 113 $body, 114 "application/octet-stream", 115 ) 116 } 117 }}; 118}