pub trait Handler:
Send
+ Sync
+ 'static {
type Connection: Send + 'static;
// Required methods
fn connect(&self, connect: &Connect<'_>) -> Option<Self::Connection>;
fn message(
&self,
conn: &mut Self::Connection,
message: Inbound,
size: usize,
) -> bool;
fn signed(
&self,
conn: &mut Self::Connection,
message: Value,
size: usize,
) -> bool;
fn disconnect(&self, conn: Self::Connection);
// Provided method
fn presence(&self, event: Presence) { ... }
}Expand description
What the server tells the application. Each connection’s calls come in order on the connection’s own task: connect, its messages, disconnect. They run on the runtime’s worker threads and should return fast; a handler hands long work to a task of its own.
A call that panics closes its connection (1011) and nothing else: the
server cleans the connection up, and disconnect still comes for one
that connect took.
Required Associated Types§
Sourcetype Connection: Send + 'static
type Connection: Send + 'static
What the handler keeps for one connection, from connect to
disconnect.
Required Methods§
Sourcefn connect(&self, connect: &Connect<'_>) -> Option<Self::Connection>
fn connect(&self, connect: &Connect<'_>) -> Option<Self::Connection>
The application learns of a connection. None when it has no room for it now: the client is told to come back later (1013).
Sourcefn message(
&self,
conn: &mut Self::Connection,
message: Inbound,
size: usize,
) -> bool
fn message( &self, conn: &mut Self::Connection, message: Inbound, size: usize, ) -> bool
A client’s message; size is its size on the wire. False when there
is no room for it: it is dropped, and one of a 3.2 client’s outbox is
refused (busy), which its client hears.
Sourcefn signed(
&self,
conn: &mut Self::Connection,
message: Value,
size: usize,
) -> bool
fn signed( &self, conn: &mut Self::Connection, message: Value, size: usize, ) -> bool
A signed message that passed every check: its body, as the client
signed it. False when there is no room for it: the client hears
busy and may send it again with the same nonce.
Sourcefn disconnect(&self, conn: Self::Connection)
fn disconnect(&self, conn: Self::Connection)
The connection ended. Only a connection connect took gets here.
Provided Methods§
Sourcefn presence(&self, event: Presence)
fn presence(&self, event: Presence)
A user’s first connection joined a topic with presence, or its last
one left. Called on whichever thread made the change: a connection’s
own task (from inside connect when it subscribes with presence, and
from its cleanup), the caller of Publisher::subscribe,
unsubscribe or update_presence, the presence sweep, or a cluster
link. A lock held across those calls must not be taken here too.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".