pub enum Dispatch<Req: JsonRpcRequest = UntypedMessage, Notif: JsonRpcNotification = UntypedMessage> {
Request(Req, Responder<Req::Response>),
Notification(Notif),
Response(Result<Req::Response, Error>, ResponseRouter<Req::Response>),
}Expand description
An incoming request, notification, or response being dispatched through handlers. Requests include the context used to answer them; responses include the context used to route them to the local requester.
Type parameters allow specifying the concrete request and notification types.
By default, both are UntypedMessage for dynamic dispatch.
The request context’s response type matches the request’s response type.
Variants§
Request(Req, Responder<Req::Response>)
Incoming request and the context where the response should be sent.
Notification(Notif)
Incoming notification.
Response(Result<Req::Response, Error>, ResponseRouter<Req::Response>)
Incoming response to a request we sent.
The first field is the response result (success or error from the remote). The second field is the context for forwarding the response to its destination (typically a waiting oneshot channel).
Implementations§
Source§impl<Req: JsonRpcRequest, Notif: JsonRpcNotification> Dispatch<Req, Notif>
impl<Req: JsonRpcRequest, Notif: JsonRpcNotification> Dispatch<Req, Notif>
Sourcepub fn map<Req1, Notif1>(
self,
map_request: impl FnOnce(Req, Responder<Req::Response>) -> (Req1, Responder<Req1::Response>),
map_notification: impl FnOnce(Notif) -> Notif1,
) -> Dispatch<Req1, Notif1>
pub fn map<Req1, Notif1>( self, map_request: impl FnOnce(Req, Responder<Req::Response>) -> (Req1, Responder<Req1::Response>), map_notification: impl FnOnce(Notif) -> Notif1, ) -> Dispatch<Req1, Notif1>
Map the request and notification types to new types.
Note: Response variants are passed through unchanged since they don’t contain a parseable message payload.
Sourcepub fn to_untyped_message(&self) -> Result<UntypedMessage, Error>
pub fn to_untyped_message(&self) -> Result<UntypedMessage, Error>
Convert the message in self to an untyped message.
Note: Response variants don’t have an untyped message representation. This returns an error for Response variants.
Sourcepub fn into_untyped_dispatch(self) -> Result<Dispatch, Error>
pub fn into_untyped_dispatch(self) -> Result<Dispatch, Error>
Convert self to an untyped message context.
Note: Response variants cannot be converted. This returns an error for Response variants.
Source§impl Dispatch
impl Dispatch
Sourcepub fn has_field(&self, field_name: &str) -> bool
pub fn has_field(&self, field_name: &str) -> bool
True if this message has a field with the given name.
Returns false for Response variants.
Sourcepub fn into_notification<N: JsonRpcNotification>(
self,
) -> Result<Result<N, Dispatch>, Error>
pub fn into_notification<N: JsonRpcNotification>( self, ) -> Result<Result<N, Dispatch>, Error>
Try to parse this as a notification of the given type.
§Returns
Ok(Ok(typed))if this is a notification of the requested typeOk(Err(self))if this is not a matching notificationErrif its method matches the requested type but parsing fails
Sourcepub fn into_request<Req: JsonRpcRequest>(
self,
) -> Result<Result<(Req, Responder<Req::Response>), Dispatch>, Error>
pub fn into_request<Req: JsonRpcRequest>( self, ) -> Result<Result<(Req, Responder<Req::Response>), Dispatch>, Error>
Try to parse this as a request of the given type.
§Returns
Ok(Ok(typed))if this is a request of the requested typeOk(Err(self))if this is not a matching requestErrif its method matches the requested type but parsing fails