From 44bcad7eda5a020ded984ff02b0c32f24a383f97 Mon Sep 17 00:00:00 2001 From: DJMrTV Date: Sat, 1 Feb 2025 20:59:21 +0100 Subject: [PATCH] fix(protocols): fix macro --- src/protocols/mod.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/protocols/mod.rs b/src/protocols/mod.rs index 1dd1c98..1b9e3dd 100644 --- a/src/protocols/mod.rs +++ b/src/protocols/mod.rs @@ -3,21 +3,28 @@ pub mod server; #[macro_export] macro_rules! define_protocol { ($id:literal $( <$lifetime:lifetime> )?($($varname:ident : $ty:ty),*) => {$($func_id:literal => $func:path),*} ) => { - fn protocol $( <$lifetime> )? (rmcmessage: &RMCMessage, $($varname : $ty,)*) -> Option{ + fn protocol $( <$lifetime> )? (rmcmessage: &RMCMessage, $($varname : $ty),*) -> Option{ if rmcmessage.protocol_id != $id{ return None; } - let response_result = match rmcmessage.method_id{ + let response_function = match rmcmessage.method_id{ $( - $func_id => $func(rmcmessage), - ),* + $func_id => $func, + )* _ => { error!("invalid method id sent to protocol {}: {:?}", $id, rmcmessage.method_id); - rmcmessage.error_result_with_code(ErrorCode::Core_NotImplemented) + return Some( + RMCResponse{ + protocol_id: $id, + response_result: rmcmessage.error_result_with_code(ErrorCode::Core_NotImplemented) + } + ); } }; + let response_result = response_function(rmcmessage, $($varname),*); + Some(RMCResponse{ protocol_id: $id, response_result