Expand description
rpc::router module provides the type and implementation for json rpc routing.
It has the following constructs:
RpcRouterholds the HashMap ofmethod_name: Box<dyn RpcHandlerWrapperTrait>.RpcHandlertrait 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).IntoParamsis the trait to implement to instruct how to go fromOption<Value>json-rpc params to the handler’s param types.IntoParamshas a defaultinto_paramsimplementation that will return an error if the params are missing.
#[derive(Deserialize)]
pub struct ParamsIded {
id: i64,
}
impl IntoParams for ParamsIded {}- For custom
IntoParamsbehavior, implement theIntoParams::into_paramsfunction. - Implementing
IntoDefaultParamson a type that implementsDefaultwill auto-implementIntoParamsand callT::default()when the paramsOption<Value>is None.
Macros§
- impl_
handler_ pair - Macro generatring the Rpc Handler implementations for zero or more FromResources with the last argument being IntoParams and one with not last IntoParams argument.
- resources_
builder - A simple macro to create a new RpcRouterInner and add each rpc handler-compatible function along with their corresponding names.
- router_
builder - A simple macro to create a new RouterBuider from a list of handlers and optionaly a list of resources
Structs§
- Call
Error - Call
Response - Handler
Error - Request
- The raw JSON-RPC request object, serving as the foundation for RPC routing.
- Resources
- Resources
Builder - Router
- Router
Builder
Enums§
- Error
- From
Resources Error - Request
Parsing Error - The RPC Request Parsing error is used when utilizing
value.try_into()?orRequest::from_value(value). The design intent is to validate and provide as much context as possible when a specific validation fails.
Traits§
- From
Resources - Handler
- The
Handlertrait that will be implemented by rpc handler functions. - Into
Default RpcParams - Marker trait with a blanket implementation that return T::default
if the
params: Option<Value>is none. - Into
Handler Error - A trait with a default implementation that converts any application error
into a
RpcHandlerError. This allows the application code to query and extract the specified application error. - Into
Params IntoParamsallows 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_paramsmethod.
Type Aliases§
Derive Macros§
- RpcHandler
Error - Will implement
IntoHandlerErrorfor this target type. The target type must implementstd::error::Error - RpcParams
- Will implement
IntoParamsfor this target type. The target type must implementDeserialize - RpcResource
- Will implement
FromResourcesfor this target type. The target type must implementClone + Send + Sync