pub enum Dispatch<Req: JsonRpcRequest = UntypedMessage, Notif: JsonRpcNotification = UntypedMessage, P: Protocol = Raw> {
Request(Req, Responder<Req::Response, P>),
Notification(Notif),
Response(Result<Req::Response, Error>, ResponseRouter<Req::Response, P>),
}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.
P is the Protocol marker of the request handles. Typed handlers on
v1 builders receive Dispatch<Req, Notif, V1> and those on v2 builders
Dispatch<Req, Notif, V2>. The version-neutral HandleDispatchFrom
layer uses the default, Raw, whose id() is the wire ID.
Variants§
Request(Req, Responder<Req::Response, P>)
Incoming request and the context where the response should be sent.
Notification(Notif)
Incoming notification.
Response(Result<Req::Response, Error>, ResponseRouter<Req::Response, P>)
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, P: Protocol> Dispatch<Req, Notif, P>
impl<Req: JsonRpcRequest, Notif: JsonRpcNotification, P: Protocol> Dispatch<Req, Notif, P>
Sourcepub fn map<Req1, Notif1>(
self,
map_request: impl FnOnce(Req, Responder<Req::Response, P>) -> (Req1, Responder<Req1::Response, P>),
map_notification: impl FnOnce(Notif) -> Notif1,
) -> Dispatch<Req1, Notif1, P>
pub fn map<Req1, Notif1>( self, map_request: impl FnOnce(Req, Responder<Req::Response, P>) -> (Req1, Responder<Req1::Response, P>), map_notification: impl FnOnce(Notif) -> Notif1, ) -> Dispatch<Req1, Notif1, P>
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 request or notification to an untyped message.
§Errors
Returns an error for a response, which has no method params, or if the request or notification cannot encode its params.
Sourcepub fn into_untyped_dispatch(
self,
) -> Result<Dispatch<UntypedMessage, UntypedMessage, P>, Error>
pub fn into_untyped_dispatch( self, ) -> Result<Dispatch<UntypedMessage, UntypedMessage, P>, Error>
Convert self to an untyped message context.
§Errors
Returns an error for a response, or if the request or notification cannot encode its params.
Sourcepub fn id(&self) -> Option<&P::RequestId>
pub fn id(&self) -> Option<&P::RequestId>
Returns the request ID if this is a request or response, None if notification.
See Responder::id and ResponseRouter::id.
Sourcepub fn raw_id(&self) -> Option<&RawJsonRpcId>
pub fn raw_id(&self) -> Option<&RawJsonRpcId>
Returns the request ID exactly as it appears on the wire if this is a request or response, None if notification.
See Responder::raw_id and ResponseRouter::raw_id.
Source§impl<Req: JsonRpcRequest, Notif: JsonRpcNotification> Dispatch<Req, Notif, Raw>
impl<Req: JsonRpcRequest, Notif: JsonRpcNotification> Dispatch<Req, Notif, Raw>
Sourcepub fn into_protocol<Q: Protocol>(
self,
) -> Result<Dispatch<Req, Notif, Q>, Error>
pub fn into_protocol<Q: Protocol>( self, ) -> Result<Dispatch<Req, Notif, Q>, Error>
Convert this version-neutral dispatch to protocol Q’s request
handles.
§Errors
See Responder::into_protocol: this fails only for a request whose
null ID Q does not allow, with the Invalid Request error
(-32600).
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.