Crate rpc_router
source ·Expand description
rpc::router module provides the type and implementation for json rpc routing.
It has the following constructs:
RpcRouter
holds the HashMap ofmethod_name: Box<dyn RpcHandlerWrapperTrait>
.RpcHandler
trait is implemented for any async function that, with(S1, S2, ...[impl IntoParams])
, returnsweb::Result<Serialize>
where S1, S2, … are types that implementFromResources
(see router/from_resources.rs and src/resources.rs).IntoParams
is the trait to implement to instruct how to go fromOption<Value>
json-rpc params to the handler’s param types.IntoParams
has a defaultinto_params
implementation that will return an error if the params are missing.
#[derive(Deserialize)]
pub struct ParamsIded {
id: i64,
}
impl IntoParams for ParamsIded {}
- For custom
IntoParams
behavior, implement theIntoParams::into_params
function. - Implementing
IntoDefaultParams
on a type that implementsDefault
will auto-implementIntoParams
and callT::default()
when the paramsOption<Value>
is None.
Macros§
- Macro generatring the RpcHandler implementations for zero or more FromRpcResources with the last argument being IntoRpcParams and one with not last IntoRpcParams argument.
- A simple macro to create a new RpcRouter and add each rpc handler-compatible function along with their corresponding names.
Structs§
- The raw JSON-RPC request object, serving as the foundation for RPC routing.
- method, which calls the appropriate handler matching the method_name.
Enums§
Traits§
- Marker trait with a blanket implementation that return T::default if the
params: Option<Value>
is none. IntoParams
allows for converting anOption<Value>
into the necessary type for RPC handler parameters. The default implementation below will result in failure if the value isNone
. For customized behavior, users can implement their owninto_params
method.- The
Handler
trait that will be implemented by rpc handler functions.
Type Aliases§
Derive Macros§
- Will implement
IntoRpcHandlerError
for this target type. The target type must implementstd::error::Error
- Will implement
IntoRpcParams
for this target type. The target type must implementDeserialize
- Will implement
FromRpcResources
for this target type. The target type must implementClone + Send + Sync