MessageCx

Enum MessageCx 

Source
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>

Source

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>
where Req1: JrRequest<Response: Send>, Notif1: JrMessage,

Map the request and notification types to new types.

Source

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.

Source

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.

Source

pub fn to_untyped_message(&self) -> Result<UntypedMessage, Error>

Convert the message to an untyped message.

Source

pub fn id(&self) -> Option<Value>

Returns the request ID if this is a request, None if notification.

Source

pub fn method(&self) -> &str

Returns the method of the message (only available for UntypedMessage).

Source§

impl<M: JrRequest + JrNotification> MessageCx<M, M>

Source

pub fn message(&self) -> &M

Returns the message of the message (only available for UntypedMessage).

Trait Implementations§

Source§

impl<Req: Debug + JrRequest, Notif: Debug + JrMessage> Debug for MessageCx<Req, Notif>
where Req::Response: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Req, Notif> Freeze for MessageCx<Req, Notif>
where Req: Freeze, Notif: Freeze,

§

impl<Req = UntypedMessage, Notif = UntypedMessage> !RefUnwindSafe for MessageCx<Req, Notif>

§

impl<Req, Notif> Send for MessageCx<Req, Notif>

§

impl<Req = UntypedMessage, Notif = UntypedMessage> !Sync for MessageCx<Req, Notif>

§

impl<Req, Notif> Unpin for MessageCx<Req, Notif>
where Req: Unpin, Notif: Unpin,

§

impl<Req = UntypedMessage, Notif = UntypedMessage> !UnwindSafe for MessageCx<Req, Notif>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more