JrMessageHandler

Trait JrMessageHandler 

Source
pub trait JrMessageHandler {
    type Role: JrRole;

    // Required methods
    async fn handle_message(
        &mut self,
        message: MessageCx,
        cx: JrConnectionCx<Self::Role>,
    ) -> Result<Handled<MessageCx>, Error>;
    fn describe_chain(&self) -> impl Debug;
}
Expand description

Handlers are invoked when new messages arrive at the JrConnection. They have a chance to inspect the method and parameters and decide whether to “claim” the request (i.e., handle it). If they do not claim it, the request will be passed to the next handler.

Required Associated Types§

Source

type Role: JrRole

The role type for this handler’s connection.

Required Methods§

Source

async fn handle_message( &mut self, message: MessageCx, cx: JrConnectionCx<Self::Role>, ) -> Result<Handled<MessageCx>, Error>

Attempt to claim an incoming message (request or notification).

§Important: do not block

The server will not process new messages until this handler returns. You should avoid blocking in this callback unless you wish to block the server (e.g., for rate limiting). The recommended approach to manage expensive operations is to the JrConnectionCx::spawn method available on the message context.

§Parameters
  • cx - The context of the request. This gives access to the request ID and the method name and is used to send a reply; can also be used to send other messages to the other party.
  • params - The parameters of the request.
§Returns
  • Ok(Handled::Yes) if the message was claimed. It will not be propagated further.
  • Ok(Handled::No(message)) if not; the (possibly changed) message will be passed to the remaining handlers.
  • Err if an internal error occurs (this will bring down the server).
Source

fn describe_chain(&self) -> impl Debug

Returns a debug description of the handler chain for diagnostics

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<H1, H2> JrMessageHandler for ChainedHandler<H1, H2>
where H1: JrMessageHandler, H2: JrMessageHandler<Role = H1::Role>,

Source§

impl<H: JrMessageHandler> JrMessageHandler for NamedHandler<H>

Source§

impl<H: JrMessageHandlerSend> JrMessageHandler for H

Source§

impl<Role, End: JrEndpoint, Notif, F, T> JrMessageHandler for NotificationHandler<Role, End, Notif, F>
where Role: HasEndpoint<End> + JrRole, Notif: JrNotification, F: AsyncFnMut(Notif, JrConnectionCx<Role>) -> Result<T, Error>, T: IntoHandled<(Notif, JrConnectionCx<Role>)>,

Source§

type Role = Role

Source§

impl<Role, End: JrEndpoint, Req, F, T> JrMessageHandler for RequestHandler<Role, End, Req, F>
where Role: HasEndpoint<End> + JrRole, Req: JrRequest, F: AsyncFnMut(Req, JrRequestCx<Req::Response>, JrConnectionCx<Role>) -> Result<T, Error>, T: IntoHandled<(Req, JrRequestCx<Req::Response>)>,

Source§

type Role = Role

Source§

impl<Role, End: JrEndpoint, Req: JrRequest, Notif: JrNotification, F, T> JrMessageHandler for MessageHandler<Role, End, Req, Notif, F>
where Role: HasEndpoint<End> + JrRole, F: AsyncFnMut(MessageCx<Req, Notif>, JrConnectionCx<Role>) -> Result<T, Error>, T: IntoHandled<MessageCx<Req, Notif>>,

Source§

type Role = Role

Source§

impl<Role: JrRole> JrMessageHandler for NullHandler<Role>

Source§

type Role = Role