pub enum MessageCx<Req: JrRequest = UntypedMessage, Notif: JrMessage = UntypedMessage> {
Request(Req, JrRequestCx<Req::Response>),
Notification(Notif),
}Expand description
An enum capturing an in-flight request or notification. In the case of a request, also includes the context used to respond to the request.
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, JrRequestCx<Req::Response>)
Incoming request and the context where the response should be sent.
Notification(Notif)
Incoming notification.
Implementations§
Source§impl<Req: JrRequest, Notif: JrMessage> MessageCx<Req, Notif>
impl<Req: JrRequest, Notif: JrMessage> MessageCx<Req, Notif>
Sourcepub fn map<Req1, Notif1>(
self,
map_request: impl FnOnce(Req, JrRequestCx<Req::Response>) -> (Req1, JrRequestCx<Req1::Response>),
map_notification: impl FnOnce(Notif) -> Notif1,
) -> MessageCx<Req1, Notif1>
pub fn map<Req1, Notif1>( self, map_request: impl FnOnce(Req, JrRequestCx<Req::Response>) -> (Req1, JrRequestCx<Req1::Response>), map_notification: impl FnOnce(Notif) -> Notif1, ) -> MessageCx<Req1, Notif1>
Map the request and notification types to new types.
Sourcepub fn respond_with_error<Role: JrRole>(
self,
error: Error,
cx: JrConnectionCx<Role>,
) -> Result<(), Error>
pub fn respond_with_error<Role: JrRole>( self, error: Error, cx: JrConnectionCx<Role>, ) -> Result<(), Error>
Respond to the message with an error.
If this message is a request, this error becomes the reply to the request.
If this message is a notification, the error is sent as a notification.
Sourcepub fn erase_to_json(self) -> Result<MessageCx, Error>
pub fn erase_to_json(self) -> Result<MessageCx, Error>
Convert to a JrRequestCx that expects a JSON value
and which checks (dynamically) that the JSON value it receives
can be converted to T.
Sourcepub fn to_untyped_message(&self) -> Result<UntypedMessage, Error>
pub fn to_untyped_message(&self) -> Result<UntypedMessage, Error>
Convert the message to an untyped message.