🏗️ Elegant & Highly Performant Async Gemini Server Framework for the Modern Age
async framework gemini-protocol protocol gemini rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(macros): async response macros

Fuwn 0f16e32d 2f7e1b76

+53 -18
+2
Cargo.toml
··· 38 38 matchit = "0.6.0" 39 39 40 40 tree_magic = { version = "0.2.3", optional = true } # MIME 41 + 42 + paste = "1.0.12" # Token Pasting
+4
examples/windmark.rs
··· 214 214 router.mount("/async-nothing", |_| { 215 215 async { Response::success("This is an async route.") } 216 216 }); 217 + router.mount( 218 + "/async-macro", 219 + windmark::success_async!(async { "hi" }.await), 220 + ); 217 221 218 222 router.run().await 219 223 }
+47 -18
src/response/macros.rs
··· 16 16 // Copyright (C) 2022-2022 Fuwn <contact@fuwn.me> 17 17 // SPDX-License-Identifier: GPL-3.0-only 18 18 19 - macro_rules! response { 19 + macro_rules! sync_response { 20 20 ($($name:tt),*) => { 21 21 $( 22 22 /// Trailing commas are not supported at the moment! ··· 33 33 }; 34 34 } 35 35 36 - response!(input); 37 - response!(sensitive_input); 38 - response!(success); 36 + macro_rules! async_response { 37 + ($($name:tt),*) => { 38 + $(::paste::paste! { 39 + /// Trailing commas are not supported at the moment! 40 + #[macro_export] 41 + macro_rules! [< $name _async >] { 42 + ($body:expr /* $(,)? */) => { 43 + |_: ::windmark::context::RouteContext<'_>| async { ::windmark::Response::$name($body) } 44 + }; 45 + ($context:ident, $body:expr /* $(,)? */) => { 46 + |$context: ::windmark::context::RouteContext<'_>| async { ::windmark::Response::$name($body) } 47 + }; 48 + } 49 + })* 50 + }; 51 + } 52 + 53 + macro_rules! response { 54 + ($($name:tt),* $(,)?) => { 55 + $( 56 + sync_response!($name); 57 + async_response!($name); 58 + )* 59 + }; 60 + } 61 + 62 + response!( 63 + input, 64 + sensitive_input, 65 + success, 66 + temporary_redirect, 67 + permanent_redirect, 68 + temporary_failure, 69 + server_unavailable, 70 + cgi_error, 71 + proxy_error, 72 + slow_down, 73 + permanent_failure, 74 + not_found, 75 + gone, 76 + proxy_refused, 77 + bad_request, 78 + client_certificate_required, 79 + certificate_not_valid, 80 + ); 81 + 39 82 #[cfg(feature = "auto-deduce-mime")] 40 83 response!(binary_success_auto); 41 - response!(temporary_redirect); 42 - response!(permanent_redirect); 43 - response!(temporary_failure); 44 - response!(server_unavailable); 45 - response!(cgi_error); 46 - response!(proxy_error); 47 - response!(slow_down); 48 - response!(permanent_failure); 49 - response!(not_found); 50 - response!(gone); 51 - response!(proxy_refused); 52 - response!(bad_request); 53 - response!(client_certificate_required); 54 - response!(certificate_not_valid); 55 84 56 85 /// Trailing commas are not supported at the moment! 57 86 #[macro_export]