pub trait WebsocketHandlerwhere
Self: Sized,{
type Message: Receivable;
// Required methods
fn accept(
address: SocketAddr,
request: &WebsocketRequest,
response: WebsocketResponse,
) -> Result<(WebsocketResponse, Self), ExitReason>;
fn websocket_handle(
&mut self,
message: WebsocketMessage,
) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send;
// Provided methods
fn websocket_init(
&mut self,
) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send { ... }
fn websocket_info(
&mut self,
info: Message<Self::Message>,
) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send { ... }
fn terminate(
&mut self,
reason: ExitReason,
) -> impl Future<Output = ()> + Send { ... }
}Expand description
A process that handles websocket messages.
Required Associated Types§
Sourcetype Message: Receivable
type Message: Receivable
The message type that this handler will use.
Required Methods§
Sourcefn accept(
address: SocketAddr,
request: &WebsocketRequest,
response: WebsocketResponse,
) -> Result<(WebsocketResponse, Self), ExitReason>
fn accept( address: SocketAddr, request: &WebsocketRequest, response: WebsocketResponse, ) -> Result<(WebsocketResponse, Self), ExitReason>
A callback used to accept or deny a request for a websocket upgrade.
You can extract information from the request and put it in your handler state.
Sourcefn websocket_handle(
&mut self,
message: WebsocketMessage,
) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send
fn websocket_handle( &mut self, message: WebsocketMessage, ) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send
Invoked to handle messages received from the websocket.
Provided Methods§
Sourcefn websocket_init(
&mut self,
) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send
fn websocket_init( &mut self, ) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send
An optional callback that happens before the first message is sent/received from the websocket.
This is the first callback that happens in the process responsible for the websocket.
Sourcefn websocket_info(
&mut self,
info: Message<Self::Message>,
) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send
fn websocket_info( &mut self, info: Message<Self::Message>, ) -> impl Future<Output = Result<Option<WebsocketCommands>, ExitReason>> + Send
Invoked to handle messages from processes and system messages.
Sourcefn terminate(&mut self, reason: ExitReason) -> impl Future<Output = ()> + Send
fn terminate(&mut self, reason: ExitReason) -> impl Future<Output = ()> + Send
Invoked when the handler is about to exit. It should do any cleanup required.
terminate is useful for cleanup that requires access to the WebsocketHandler’s state. However, it is not
guaranteed that terminate is called when a WebsocketHandler exits. Therefore, important cleanup should be done
using process links and/or monitors. A monitoring process will receive the same reason that would be passed to terminate.
terminate is called if:
- The websocket connection closes for whatever reason.
- A callback (except
accept) returns stop with a given reason.
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.