use crate::RpcResources;
#[macro_export]
macro_rules! impl_rpc_handler_pair {
($K:ty, $($T:ident),*) => {
impl<F, Fut, $($T,)* P, R, E> $crate::RpcHandler<($($T,)*), (P,), R> for F
where
F: FnOnce($($T,)* P) -> Fut + Clone + Send + 'static,
$( $T: $crate::FromRpcResources+ Clone + Send + Sync + 'static, )*
P: $crate::IntoRpcParams + Send + Sync + 'static,
R: serde::Serialize + Send + Sync + 'static,
E: $crate::IntoRpcHandlerError,
Fut: futures::Future<Output = core::result::Result<R, E>> + Send,
{
type Future = $crate::handler::PinFutureValue;
#[allow(unused)] fn call(
self,
resources: RpcResources,
params_value: Option<serde_json::Value>,
) -> Self::Future {
Box::pin(async move {
let param = P::into_params(params_value)?;
let res = self(
$( $T::from_resources(&resources)?, )*
param,
).await;
match res {
Ok(result) => Ok(serde_json::to_value(result)?),
Err(ex) => todo!(),
}
})
}
}
impl<F, Fut, $($T,)* R, E> $crate::RpcHandler<($($T,)*), (), R> for F
where
F: FnOnce($($T,)*) -> Fut + Clone + Send + 'static,
$( $T: $crate::FromRpcResources + Clone + Send + Sync + 'static, )*
R: serde::Serialize + Send + Sync + 'static,
E: $crate::IntoRpcHandlerError,
Fut: futures::Future<Output = core::result::Result<R, E>> + Send,
{
type Future = $crate::handler::PinFutureValue;
#[allow(unused)] fn call(
self,
resources: RpcResources,
_params: Option<serde_json::Value>,
) -> Self::Future {
Box::pin(async move {
let res = self(
$( $T::from_resources(&resources)?, )*
).await;
match res {
Ok(result) => Ok(serde_json::to_value(result)?),
Err(ex) => todo!(),
}
})
}
}
};
}
impl_rpc_handler_pair!(RpcResources,);
impl_rpc_handler_pair!(RpcResources, T1);
impl_rpc_handler_pair!(RpcResources, T1, T2);
impl_rpc_handler_pair!(RpcResources, T1, T2, T3);
impl_rpc_handler_pair!(RpcResources, T1, T2, T3, T4);
impl_rpc_handler_pair!(RpcResources, T1, T2, T3, T4, T5);