Struct rpc_router::RpcRouter
source · pub struct RpcRouter { /* private fields */ }
Expand description
method, which calls the appropriate handler matching the method_name.
RpcRouter can be extended with other RpcRouters for composability.
Implementations§
source§impl RpcRouter
impl RpcRouter
pub fn new() -> Self
sourcepub fn add_dyn(
self,
name: &'static str,
dyn_handler: Box<dyn RpcHandlerWrapperTrait>
) -> Self
pub fn add_dyn( self, name: &'static str, dyn_handler: Box<dyn RpcHandlerWrapperTrait> ) -> Self
Add a dyn_handler to the router.
RpcRouter::new().add_dyn("method_name", my_handler_fn.into_dyn());
Note: This is the preferred way to add handlers to the router, as it
avoids monomorphization of the add function.
The RpcRouter also has a .add()
as a convenience function to just pass the function.
See RpcRouter::add
for more details.
sourcepub fn add<F, T, P, R>(self, name: &'static str, handler: F) -> Self
pub fn add<F, T, P, R>(self, name: &'static str, handler: F) -> Self
Add an handler function to the router.
RpcRouter::new().add("method_name", my_handler_fn);
Note: This is a convenient add function variant with generics,
and there will be monomorphed versions of this function
for each type passed. Use RpcRouter::add_dyn
to avoid this.
pub fn extend(self, other_router: RpcRouter) -> Self
pub async fn call( &self, method: &str, rpc_resources: RpcResources, params: Option<Value> ) -> Result<Value>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for RpcRouter
impl Send for RpcRouter
impl Sync for RpcRouter
impl Unpin for RpcRouter
impl !UnwindSafe for RpcRouter
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more