pub struct JsonRpcDispatcher<E>where
E: ToJsonRpcError,{
pub handlers: HashMap<String, Arc<dyn JsonRpcHandler<Error = E>>>,
pub default_handler: Option<Arc<dyn JsonRpcHandler<Error = E>>>,
}
Expand description
JSON-RPC method dispatcher with specific error type
Fields§
§handlers: HashMap<String, Arc<dyn JsonRpcHandler<Error = E>>>
§default_handler: Option<Arc<dyn JsonRpcHandler<Error = E>>>
Implementations§
Source§impl<E> JsonRpcDispatcher<E>where
E: ToJsonRpcError,
impl<E> JsonRpcDispatcher<E>where
E: ToJsonRpcError,
pub fn new() -> Self
Sourcepub fn register_method<H>(&mut self, method: String, handler: H)where
H: JsonRpcHandler<Error = E> + 'static,
pub fn register_method<H>(&mut self, method: String, handler: H)where
H: JsonRpcHandler<Error = E> + 'static,
Register a handler for a specific method
Sourcepub fn register_methods<H>(&mut self, methods: Vec<String>, handler: H)where
H: JsonRpcHandler<Error = E> + 'static,
pub fn register_methods<H>(&mut self, methods: Vec<String>, handler: H)where
H: JsonRpcHandler<Error = E> + 'static,
Register a handler for multiple methods
Sourcepub fn set_default_handler<H>(&mut self, handler: H)where
H: JsonRpcHandler<Error = E> + 'static,
pub fn set_default_handler<H>(&mut self, handler: H)where
H: JsonRpcHandler<Error = E> + 'static,
Set a default handler for unregistered methods
Sourcepub async fn handle_request_with_context(
&self,
request: JsonRpcRequest,
session_context: SessionContext,
) -> JsonRpcMessage
pub async fn handle_request_with_context( &self, request: JsonRpcRequest, session_context: SessionContext, ) -> JsonRpcMessage
Process a JSON-RPC request with session context and return a response
Sourcepub async fn handle_request(&self, request: JsonRpcRequest) -> JsonRpcMessage
pub async fn handle_request(&self, request: JsonRpcRequest) -> JsonRpcMessage
Process a JSON-RPC request and return a response (backward compatibility - no session context)
Sourcepub async fn handle_notification(
&self,
notification: JsonRpcNotification,
) -> Result<(), E>
pub async fn handle_notification( &self, notification: JsonRpcNotification, ) -> Result<(), E>
Process a JSON-RPC notification
Sourcepub async fn handle_notification_with_context(
&self,
notification: JsonRpcNotification,
session_context: Option<SessionContext>,
) -> Result<(), E>
pub async fn handle_notification_with_context( &self, notification: JsonRpcNotification, session_context: Option<SessionContext>, ) -> Result<(), E>
Process a JSON-RPC notification with session context
Sourcepub fn registered_methods(&self) -> Vec<String>
pub fn registered_methods(&self) -> Vec<String>
Get all registered methods
Trait Implementations§
Source§impl<E> Default for JsonRpcDispatcher<E>where
E: ToJsonRpcError,
impl<E> Default for JsonRpcDispatcher<E>where
E: ToJsonRpcError,
Auto Trait Implementations§
impl<E> Freeze for JsonRpcDispatcher<E>
impl<E> !RefUnwindSafe for JsonRpcDispatcher<E>
impl<E> Send for JsonRpcDispatcher<E>
impl<E> Sync for JsonRpcDispatcher<E>
impl<E> Unpin for JsonRpcDispatcher<E>
impl<E> !UnwindSafe for JsonRpcDispatcher<E>
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