Skip to main content

Method

Trait Method 

Source
pub trait Method<S, P, R>: Sealed {
    type Future: Future<Output = R> + Send;

    // Required method
    fn invoke(&self, server: S, params: P) -> Self::Future;
}
Expand description

A trait implemented by all valid JSON-RPC method handlers.

This trait abstracts over the following classes of functions and/or closures:

SignatureDescription
async fn f(&self) -> jsonrpc::Result<R>Request without parameters
async fn f(&self, params: P) -> jsonrpc::Result<R>Request with required parameters
async fn f(&self)Notification without parameters
async fn f(&self, params: P)Notification with parameters

Required Associated Types§

Source

type Future: Future<Output = R> + Send

The future response value.

Required Methods§

Source

fn invoke(&self, server: S, params: P) -> Self::Future

Invokes the method with the given server receiver and parameters.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F, S, P, R, Fut> Method<S, (P,), R> for F
where F: Fn(S, P) -> Fut, P: DeserializeOwned, Fut: Future<Output = R> + Send,

Support JSON-RPC methods with params.

Source§

type Future = Fut

Source§

impl<F, S, R, Fut> Method<S, (), R> for F
where F: Fn(S) -> Fut, Fut: Future<Output = R> + Send,

Support parameter-less JSON-RPC methods.

Source§

type Future = Fut