From e051a0376b9830c0364c40cf877a5d66efdb8b68 Mon Sep 17 00:00:00 2001 From: Sayan Nandan Date: Wed, 10 Mar 2021 14:56:43 +0530 Subject: [PATCH] Improve `gen_match!` macro to use path matches Signed-off-by: Sayan Nandan --- server/src/queryengine/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/queryengine/mod.rs b/server/src/queryengine/mod.rs index a129cafb..09b690c5 100644 --- a/server/src/queryengine/mod.rs +++ b/server/src/queryengine/mod.rs @@ -110,12 +110,18 @@ pub async fn execute_simple(db: &CoreDB, con: &mut Con<'_>, buf: ActionGroup) -> } #[macro_export] +/// A match generator macro built specifically for the `crate::queryengine::execute_simple` function +/// +/// **NOTE:** This macro needs _paths_ for both sides of the $x => $y, to produce something sensible macro_rules! gen_match { - ($pre:ident, $db:ident, $con:ident, $buf:ident, $($x1:ident::$x2:ident => $y1:ident::$y2:ident::$y3:ident),*) => { + ($pre:ident, $db:ident, $con:ident, $buf:ident, $($x:path => $y:path),*) => { match $pre.as_str() { + // First repeat over all the $x => $y patterns, passing in the variables + // and adding .await calls and adding the `?` $( - $x1::$x2 => $y1::$y2::$y3($db, $con, $buf).await?, + $x => $y($db, $con, $buf).await?, )* + // Now add the final case where no action is matched _ => { $con.write_response(responses::fresp::R_UNKNOWN_ACTION.to_owned()) .await?;