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 FromResources
arguments (for now) and one optionalsimpl 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, asFnOnce
, enabling them to be cloned with none or negligible performance impact, thus facilitating the use of RpcRoute dynamic dispatch. T
is the tuple ofimpl FromResources
arguments.P
is theimpl IntoParams
argument.
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.