feat(protocols): extend functionality of protocol macro
This commit is contained in:
parent
ffe4084ba3
commit
1679590bf3
6 changed files with 38 additions and 12 deletions
|
|
@ -2,8 +2,8 @@ pub mod auth;
|
|||
pub mod server;
|
||||
#[macro_export]
|
||||
macro_rules! define_protocol {
|
||||
($id:literal => {$($func_id:literal => $func:path),*} ) => {
|
||||
pub fn protocol(rmcmessage: &RMCMessage) -> Option<RMCResponse>{
|
||||
($id:literal $( <$lifetime:lifetime> )?($($varname:ident : $ty:ty),*) => {$($func_id:literal => $func:path),*} ) => {
|
||||
fn protocol $( <$lifetime> )? (rmcmessage: &RMCMessage, $($varname : $ty,)*) -> Option<RMCResponse>{
|
||||
if rmcmessage.protocol_id != $id{
|
||||
return None;
|
||||
}
|
||||
|
|
@ -23,5 +23,16 @@ macro_rules! define_protocol {
|
|||
response_result
|
||||
})
|
||||
}
|
||||
|
||||
pub fn bound_protocol$(<$lifetime>)?($($varname : $ty,)*) -> Box<dyn Fn(&RMCMessage) -> Option<RMCResponse> + Send + Sync $( + $lifetime)?>{
|
||||
Box::new(
|
||||
move |v| {
|
||||
$(
|
||||
let $varname = $varname.clone();
|
||||
)*
|
||||
protocol(v, $($varname,)*)
|
||||
}
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue