pub trait RpcHandler<T, P, R>: Clone
where T: Send + Sync + 'static, P: Send + Sync + 'static, R: Send + Sync + 'static,
{ type Future: Future<Output = Result<Value>> + Send + 'static; // Required method fn call( self, rpc_resources: RpcResources, params: Option<Value> ) -> Self::Future; // Provided method fn into_dyn(self) -> Box<dyn RpcHandlerWrapperTrait> where Self: Sized + Send + Sync + 'static { ... } }
Expand description

The Handler trait that will be implemented by rpc handler functions.

Key points:

  • Rpc handler functions are asynchronous, thus returning a Future of Result.
  • The call format is normalized to two impl FromResources arguments (for now) and one optionals impl IntoParams, which represent the json-rpc’s optional value.
  • into_box is a convenient method for converting a RpcHandler into a Boxed dyn RpcHandlerWrapperTrait, allowing for dynamic dispatch by the Router.
  • A RpcHandler will typically be implemented for static functions, as FnOnce, enabling them to be cloned with none or negligible performance impact, thus facilitating the use of RpcRoute dynamic dispatch.
  • T is the tuple of impl FromResources arguments.
  • P is the impl IntoParams argument.

Required Associated Types§

source

type Future: Future<Output = Result<Value>> + Send + 'static

The type of future calling this handler returns.

Required Methods§

source

fn call( self, rpc_resources: RpcResources, params: Option<Value> ) -> Self::Future

Call the handler.

Provided Methods§

source

fn into_dyn(self) -> Box<dyn RpcHandlerWrapperTrait>
where Self: Sized + Send + Sync + 'static,

Convert this RpcHandler into a Boxed dyn RpcHandlerWrapperTrait, for dynamic dispatch by the Router.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<F, Fut, P, R, E> RpcHandler<(), (P,), R> for F
where F: FnOnce(P) -> Fut + Clone + Send + 'static, P: IntoRpcParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, R, E> RpcHandler<(), (), R> for F
where F: FnOnce() -> Fut + Clone + Send + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, T1, P, R, E> RpcHandler<(T1,), (P,), R> for F
where F: FnOnce(T1, P) -> Fut + Clone + Send + 'static, T1: FromRpcResources + Clone + Send + Sync + 'static, P: IntoRpcParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, T1, R, E> RpcHandler<(T1,), (), R> for F
where F: FnOnce(T1) -> Fut + Clone + Send + 'static, T1: FromRpcResources + Clone + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, T1, T2, P, R, E> RpcHandler<(T1, T2), (P,), R> for F
where F: FnOnce(T1, T2, P) -> Fut + Clone + Send + 'static, T1: FromRpcResources + Clone + Send + Sync + 'static, T2: FromRpcResources + Clone + Send + Sync + 'static, P: IntoRpcParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, T1, T2, R, E> RpcHandler<(T1, T2), (), R> for F
where F: FnOnce(T1, T2) -> Fut + Clone + Send + 'static, T1: FromRpcResources + Clone + Send + Sync + 'static, T2: FromRpcResources + Clone + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, T1, T2, T3, P, R, E> RpcHandler<(T1, T2, T3), (P,), R> for F
where F: FnOnce(T1, T2, T3, P) -> Fut + Clone + Send + 'static, T1: FromRpcResources + Clone + Send + Sync + 'static, T2: FromRpcResources + Clone + Send + Sync + 'static, T3: FromRpcResources + Clone + Send + Sync + 'static, P: IntoRpcParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, T1, T2, T3, R, E> RpcHandler<(T1, T2, T3), (), R> for F
where F: FnOnce(T1, T2, T3) -> Fut + Clone + Send + 'static, T1: FromRpcResources + Clone + Send + Sync + 'static, T2: FromRpcResources + Clone + Send + Sync + 'static, T3: FromRpcResources + Clone + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, T1, T2, T3, T4, P, R, E> RpcHandler<(T1, T2, T3, T4), (P,), R> for F
where F: FnOnce(T1, T2, T3, T4, P) -> Fut + Clone + Send + 'static, T1: FromRpcResources + Clone + Send + Sync + 'static, T2: FromRpcResources + Clone + Send + Sync + 'static, T3: FromRpcResources + Clone + Send + Sync + 'static, T4: FromRpcResources + Clone + Send + Sync + 'static, P: IntoRpcParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, T1, T2, T3, T4, R, E> RpcHandler<(T1, T2, T3, T4), (), R> for F
where F: FnOnce(T1, T2, T3, T4) -> Fut + Clone + Send + 'static, T1: FromRpcResources + Clone + Send + Sync + 'static, T2: FromRpcResources + Clone + Send + Sync + 'static, T3: FromRpcResources + Clone + Send + Sync + 'static, T4: FromRpcResources + Clone + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, T1, T2, T3, T4, T5, P, R, E> RpcHandler<(T1, T2, T3, T4, T5), (P,), R> for F
where F: FnOnce(T1, T2, T3, T4, T5, P) -> Fut + Clone + Send + 'static, T1: FromRpcResources + Clone + Send + Sync + 'static, T2: FromRpcResources + Clone + Send + Sync + 'static, T3: FromRpcResources + Clone + Send + Sync + 'static, T4: FromRpcResources + Clone + Send + Sync + 'static, T5: FromRpcResources + Clone + Send + Sync + 'static, P: IntoRpcParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>

source§

impl<F, Fut, T1, T2, T3, T4, T5, R, E> RpcHandler<(T1, T2, T3, T4, T5), (), R> for F
where F: FnOnce(T1, T2, T3, T4, T5) -> Fut + Clone + Send + 'static, T1: FromRpcResources + Clone + Send + Sync + 'static, T2: FromRpcResources + Clone + Send + Sync + 'static, T3: FromRpcResources + Clone + Send + Sync + 'static, T4: FromRpcResources + Clone + Send + Sync + 'static, T5: FromRpcResources + Clone + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoRpcHandlerError, Fut: Future<Output = Result<R, E>> + Send,

§

type Future = Pin<Box<dyn Future<Output = Result<Value, Error>> + Send>>