pub trait Handler<T, P, R>: Clone{
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 FromResourcesarguments (for now) and one optionalsimpl IntoParams, which represent the json-rpc’s optional value. into_boxis a convenient method for converting a RpcHandler into a Boxed dyn RpcHandlerWrapperTrait, allowing for dynamic dispatch by the Router.- A
RpcHandlerwill typically be implemented for static functions, asFnOnce, enabling them to be cloned with none or negligible performance impact, thus facilitating the use of RpcRoute dynamic dispatch. Tis the tuple ofimpl FromResourcesarguments.Pis theimpl IntoParamsargument.
Required Associated Types§
Required Methods§
Provided Methods§
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.