Trait Handler

Source
pub trait Handler<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: Resources, 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: Resources, 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<F, Fut, T1, P, R, E> Handler<(T1,), (P,), R> for F
where F: FnOnce(T1, P) -> Fut + Clone + Send + 'static, T1: FromResources + Clone + Send + Sync + 'static, P: IntoParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoHandlerError, Fut: Future<Output = Result<R, E>> + Send,

Source§

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

Source§

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

Source§

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

Source§

impl<F, Fut, T1, T2, P, R, E> Handler<(T1, T2), (P,), R> for F
where F: FnOnce(T1, T2, P) -> Fut + Clone + Send + 'static, T1: FromResources + Clone + Send + Sync + 'static, T2: FromResources + Clone + Send + Sync + 'static, P: IntoParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoHandlerError, Fut: Future<Output = Result<R, E>> + Send,

Source§

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

Source§

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

Source§

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

Source§

impl<F, Fut, T1, T2, T3, P, R, E> Handler<(T1, T2, T3), (P,), R> for F
where F: FnOnce(T1, T2, T3, P) -> Fut + Clone + Send + 'static, T1: FromResources + Clone + Send + Sync + 'static, T2: FromResources + Clone + Send + Sync + 'static, T3: FromResources + Clone + Send + Sync + 'static, P: IntoParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoHandlerError, Fut: Future<Output = Result<R, E>> + Send,

Source§

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

Source§

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

Source§

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

Source§

impl<F, Fut, T1, T2, T3, T4, P, R, E> Handler<(T1, T2, T3, T4), (P,), R> for F
where F: FnOnce(T1, T2, T3, T4, P) -> Fut + Clone + Send + 'static, T1: FromResources + Clone + Send + Sync + 'static, T2: FromResources + Clone + Send + Sync + 'static, T3: FromResources + Clone + Send + Sync + 'static, T4: FromResources + Clone + Send + Sync + 'static, P: IntoParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoHandlerError, Fut: Future<Output = Result<R, E>> + Send,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<F, Fut, T1, T2, T3, T4, T5, T6, P, R, E> Handler<(T1, T2, T3, T4, T5, T6), (P,), R> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, P) -> Fut + Clone + Send + 'static, T1: FromResources + Clone + Send + Sync + 'static, T2: FromResources + Clone + Send + Sync + 'static, T3: FromResources + Clone + Send + Sync + 'static, T4: FromResources + Clone + Send + Sync + 'static, T5: FromResources + Clone + Send + Sync + 'static, T6: FromResources + Clone + Send + Sync + 'static, P: IntoParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoHandlerError, Fut: Future<Output = Result<R, E>> + Send,

Source§

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

Source§

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

Source§

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

Source§

impl<F, Fut, T1, T2, T3, T4, T5, T6, T7, P, R, E> Handler<(T1, T2, T3, T4, T5, T6, T7), (P,), R> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, P) -> Fut + Clone + Send + 'static, T1: FromResources + Clone + Send + Sync + 'static, T2: FromResources + Clone + Send + Sync + 'static, T3: FromResources + Clone + Send + Sync + 'static, T4: FromResources + Clone + Send + Sync + 'static, T5: FromResources + Clone + Send + Sync + 'static, T6: FromResources + Clone + Send + Sync + 'static, T7: FromResources + Clone + Send + Sync + 'static, P: IntoParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoHandlerError, Fut: Future<Output = Result<R, E>> + Send,

Source§

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

Source§

impl<F, Fut, T1, T2, T3, T4, T5, T6, T7, R, E> Handler<(T1, T2, T3, T4, T5, T6, T7), (), R> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7) -> Fut + Clone + Send + 'static, T1: FromResources + Clone + Send + Sync + 'static, T2: FromResources + Clone + Send + Sync + 'static, T3: FromResources + Clone + Send + Sync + 'static, T4: FromResources + Clone + Send + Sync + 'static, T5: FromResources + Clone + Send + Sync + 'static, T6: FromResources + Clone + Send + Sync + 'static, T7: FromResources + Clone + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoHandlerError, Fut: Future<Output = Result<R, E>> + Send,

Source§

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

Source§

impl<F, Fut, T1, T2, T3, T4, T5, T6, T7, T8, P, R, E> Handler<(T1, T2, T3, T4, T5, T6, T7, T8), (P,), R> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8, P) -> Fut + Clone + Send + 'static, T1: FromResources + Clone + Send + Sync + 'static, T2: FromResources + Clone + Send + Sync + 'static, T3: FromResources + Clone + Send + Sync + 'static, T4: FromResources + Clone + Send + Sync + 'static, T5: FromResources + Clone + Send + Sync + 'static, T6: FromResources + Clone + Send + Sync + 'static, T7: FromResources + Clone + Send + Sync + 'static, T8: FromResources + Clone + Send + Sync + 'static, P: IntoParams + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoHandlerError, Fut: Future<Output = Result<R, E>> + Send,

Source§

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

Source§

impl<F, Fut, T1, T2, T3, T4, T5, T6, T7, T8, R, E> Handler<(T1, T2, T3, T4, T5, T6, T7, T8), (), R> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8) -> Fut + Clone + Send + 'static, T1: FromResources + Clone + Send + Sync + 'static, T2: FromResources + Clone + Send + Sync + 'static, T3: FromResources + Clone + Send + Sync + 'static, T4: FromResources + Clone + Send + Sync + 'static, T5: FromResources + Clone + Send + Sync + 'static, T6: FromResources + Clone + Send + Sync + 'static, T7: FromResources + Clone + Send + Sync + 'static, T8: FromResources + Clone + Send + Sync + 'static, R: Serialize + Send + Sync + 'static, E: IntoHandlerError, Fut: Future<Output = Result<R, E>> + Send,

Source§

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