Struct rpc_router::Router

source ·
pub struct Router { /* private fields */ }

Implementations§

source§

impl Router

source

pub fn builder() -> RouterBuilder

Returns a new ResourcesBuilder. This is equivalent to calling Resources::default().

source§

impl Router

source

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 and method, and includes the Result<Value, rpc_router::Error> result.

  • The rpc_router::Error includes a variant rpc_router::Error::Handler(RpcHandlerError), where RpcHandlerError allows retrieval of the application error returned by the handler through RpcHandlerError::get::<T>(&self) -> Option<T>. This mechanism enables application RPC handlers to return specific application errors while still utilizing the rpc-router result structure, thereby allowing them to retrieve their specific error type.

source

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.

source

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

source

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.

Trait Implementations§

source§

impl Clone for Router

source§

fn clone(&self) -> Router

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Router

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Router

§

impl !RefUnwindSafe for Router

§

impl Send for Router

§

impl Sync for Router

§

impl Unpin for Router

§

impl !UnwindSafe for Router

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.