pub struct Dispatcher { /* private fields */ }Expand description
Routes inbound JSON-RPC method calls to async handlers.
Implementations§
Source§impl Dispatcher
impl Dispatcher
Sourcepub fn register<F, Fut>(&self, method: impl Into<String>, handler: F)where
F: Fn(Value, CancellationToken) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HandlerResult> + Send + 'static,
pub fn register<F, Fut>(&self, method: impl Into<String>, handler: F)where
F: Fn(Value, CancellationToken) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HandlerResult> + Send + 'static,
Register a handler for method. Replaces any previously registered handler.
Sourcepub async fn dispatch(
&self,
id: &RequestId,
method: &str,
params: Value,
) -> Result<HandlerResult, DispatchError>
pub async fn dispatch( &self, id: &RequestId, method: &str, params: Value, ) -> Result<HandlerResult, DispatchError>
Dispatch a request. Returns the handler’s result.
The supplied id is used to register a cancellation token so a later
$/cancelRequest for the same id can trip the handler.
§Errors
Returns DispatchError::UnknownMethod if no handler is registered.
Trait Implementations§
Source§impl Clone for Dispatcher
impl Clone for Dispatcher
Source§fn clone(&self) -> Dispatcher
fn clone(&self) -> Dispatcher
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Dispatcher
impl Debug for Dispatcher
Source§impl Default for Dispatcher
impl Default for Dispatcher
Source§fn default() -> Dispatcher
fn default() -> Dispatcher
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for Dispatcher
impl RefUnwindSafe for Dispatcher
impl Send for Dispatcher
impl Sync for Dispatcher
impl Unpin for Dispatcher
impl UnsafeUnpin for Dispatcher
impl UnwindSafe for Dispatcher
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