Skip to main content

Handler

Trait Handler 

Source
pub trait Handler:
    Send
    + Sync
    + 'static {
    // Required method
    fn dispatch(
        &self,
        req: Request,
        origin: PeerOrigin,
        writer: &SharedWriter,
        conn: u64,
    ) -> Response;

    // Provided methods
    fn on_connect(&self, _origin: PeerOrigin, _conn: u64) { ... }
    fn streams(&self, _method: &str) -> bool { ... }
    fn on_disconnect(&self, _origin: PeerOrigin, _conn: u64) { ... }
}
Expand description

The embedder’s domain seam. The framework owns the transport, the framing, the connection lifecycle, and the subscription registry; the Handler supplies the meaning — which tools/resources exist, who may call/read/subscribe to what.

Lifecycle (initialize / server/discover / ping) is NOT routed here: a handler answers it once, version-aware, by calling lifecycle_response at the top of its dispatch (so the multi-version negotiation lives in one place). Everything else — tools/*, resources/*, and any custom method — flows through dispatch.

Required Methods§

Source

fn dispatch( &self, req: Request, origin: PeerOrigin, writer: &SharedWriter, conn: u64, ) -> Response

Route one request to a response. origin is the caller’s trust domain; writer/conn identify the connection so a resources/subscribe can register a push target via register_subscriber. Called from the connection’s own thread — implementations do their own locking.

Provided Methods§

Source

fn on_connect(&self, _origin: PeerOrigin, _conn: u64)

Called once when a connection is accepted (before its first request), for logging/metrics. Default: nothing.

Source

fn streams(&self, _method: &str) -> bool

Whether method responds as a SERVER STREAM (several frames pushed through the dispatch writer, the returned Response being the final frame). The HTTP transport upgrades such a request to a text/event-stream response instead of a unary application/json one. Default: nothing streams.

Source

fn on_disconnect(&self, _origin: PeerOrigin, _conn: u64)

Called once when a connection’s reader loop ends. The framework has already dropped the connection’s subscriptions; this is for logging/metrics or any embedder-side per-connection cleanup. Default: nothing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§