Struct rpc_router::Router
source · pub struct Router { /* private fields */ }
Implementations§
source§impl Router
impl Router
sourcepub fn builder() -> RouterBuilder
pub fn builder() -> RouterBuilder
Returns a new ResourcesBuilder
.
This is equivalent to calling Resources::default()
.
source§impl Router
impl Router
sourcepub async fn call(&self, rpc_request: Request) -> CallResult
pub async fn call(&self, rpc_request: Request) -> CallResult
Performs the RPC call for a given RpcRequest object (i.e., .id, .method, .params
)
with the eventual resources of the router.
To add additional resources on top of the router’s resources, call .call_with_resources(request, resources)
-
Returns an CallResult that echoes the
id
andmethod
, and includes theResult<Value, rpc_router::Error>
result. -
The
rpc_router::Error
includes a variantrpc_router::Error::Handler(RpcHandlerError)
, whereRpcHandlerError
allows retrieval of the application error returned by the handler throughRpcHandlerError::get::<T>(&self) -> Option<T>
. This mechanism enables application RPC handlers to return specific application errors while still utilizing therpc-router
result structure, thereby allowing them to retrieve their specific error type.
sourcepub async fn call_with_resources(
&self,
rpc_request: Request,
additional_resources: Resources
) -> CallResult
pub async fn call_with_resources( &self, rpc_request: Request, additional_resources: Resources ) -> CallResult
Similar to .call(...)
, but takes an additional Resources
parameter that will be overlaid on top
of the eventual base router resources.
Note: The router will first try to get the resource from the overlay, and then, will try the base router resources.
sourcepub async fn call_route(
&self,
id: Option<Value>,
method: impl Into<String>,
params: Option<Value>
) -> CallResult
pub async fn call_route( &self, id: Option<Value>, method: impl Into<String>, params: Option<Value> ) -> CallResult
Lower level function to .call
which take all Rpc Request properties as value.
If id is None, it will be set a Value::Null
This also use router base resources.
To add additional resources on top of the router’s resources, call .call_route_with_resources(request, resources)
- method: The json-rpc method name.
-
id: The json-rpc request `.id`, which should be sent by the client. It is required to echo it back in the json-rpc response. Can be `Value::Null`, and if None, it will be set to `Value::Null`
- params: The optional json-rpc params
Returns an CallResult, where either the success value (CallResponse) or the error (CallError)
will echo back the id
and method
part of their construct
sourcepub async fn call_route_with_resources(
&self,
id: Option<Value>,
method: impl Into<String>,
params: Option<Value>,
additional_resources: Resources
) -> CallResult
pub async fn call_route_with_resources( &self, id: Option<Value>, method: impl Into<String>, params: Option<Value>, additional_resources: Resources ) -> CallResult
Similar to .call_route
, but takes an additional Resources
parameter that will be overlaid on top
of the eventual base router resources.
Note: The router will first try to get the resource from the overlay, and then, will try the base router resources.