use types::{Params, Value, Error};
use futures::BoxFuture;
pub trait Metadata: Default + Clone + Send + 'static {}
impl Metadata for () {}
pub trait RpcMethodSync: Send + Sync + 'static {
fn call(&self, params: Params) -> Result<Value, Error>;
}
pub trait RpcMethodSimple: Send + Sync + 'static {
fn call(&self, params: Params) -> BoxFuture<Value, Error>;
}
pub trait RpcMethod<T: Metadata>: Send + Sync + 'static {
fn call(&self, params: Params, meta: T) -> BoxFuture<Value, Error>;
}
pub trait RpcNotificationSimple: Send + Sync + 'static {
fn execute(&self, params: Params);
}
pub trait RpcNotification<T: Metadata>: Send + Sync + 'static {
fn execute(&self, params: Params, meta: T);
}
pub enum RemoteProcedure<T: Metadata> {
Method(Box<RpcMethod<T>>),
Notification(Box<RpcNotification<T>>)
}
impl<F: Send + Sync + 'static> RpcMethodSync for F where
F: Fn(Params) -> Result<Value, Error>,
{
fn call(&self, params: Params) -> Result<Value, Error> {
self(params)
}
}
impl<F: Send + Sync + 'static> RpcMethodSimple for F where
F: Fn(Params) -> BoxFuture<Value, Error>,
{
fn call(&self, params: Params) -> BoxFuture<Value, Error> {
self(params)
}
}
impl<F: Send + Sync + 'static> RpcNotificationSimple for F where
F: Fn(Params),
{
fn execute(&self, params: Params) {
self(params)
}
}
impl<F: Send + Sync + 'static, T> RpcMethod<T> for F where
T: Metadata,
F: Fn(Params, T) -> BoxFuture<Value, Error>,
{
fn call(&self, params: Params, meta: T) -> BoxFuture<Value, Error> {
self(params, meta)
}
}
impl<F: Send + Sync + 'static, T> RpcNotification<T> for F where
T: Metadata,
F: Fn(Params, T),
{
fn execute(&self, params: Params, meta: T) {
self(params, meta)
}
}