use crate::Handler;
use crate::handler::PinFutureValue;
use crate::{Resources, Result};
use futures::Future;
use serde_json::Value;
use std::marker::PhantomData;
use std::pin::Pin;
#[derive(Clone)]
pub struct RpcHandlerWrapper<H, T, P, R> {
handler: H,
_marker: PhantomData<(T, P, R)>,
}
impl<H, T, P, R> RpcHandlerWrapper<H, T, P, R> {
pub fn new(handler: H) -> Self {
Self {
handler,
_marker: PhantomData,
}
}
}
impl<H, T, P, R> RpcHandlerWrapper<H, T, P, R>
where
H: Handler<T, P, R> + Send + Sync + 'static,
T: Send + Sync + 'static,
P: Send + Sync + 'static,
R: Send + Sync + 'static,
{
pub fn call(&self, rpc_resources: Resources, params: Option<Value>) -> H::Future {
let handler = self.handler.clone();
Handler::call(handler, rpc_resources, params)
}
}
pub trait RpcHandlerWrapperTrait: Send + Sync {
fn call(&self, rpc_resources: Resources, params: Option<Value>) -> PinFutureValue;
}
impl<H, T, P, R> RpcHandlerWrapperTrait for RpcHandlerWrapper<H, T, P, R>
where
H: Handler<T, P, R> + Clone + Send + Sync + 'static,
T: Send + Sync + 'static,
P: Send + Sync + 'static,
R: Send + Sync + 'static,
{
fn call(
&self,
rpc_resources: Resources,
params: Option<Value>,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send>> {
Box::pin(self.call(rpc_resources, params))
}
}