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§
Required Methods§
Sourceasync fn handle_message(
&mut self,
message: MessageCx,
cx: JrConnectionCx<Self::Role>,
) -> Result<Handled<MessageCx>, Error>
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.Errif an internal error occurs (this will bring down the server).
Sourcefn describe_chain(&self) -> impl Debug
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.