WebSocketHandler

Trait WebSocketHandler 

Source
pub trait WebSocketHandler:
    Send
    + Sync
    + 'static {
    // Required methods
    fn on_connect(&self) -> impl Future<Output = ()> + Send;
    fn on_message(
        &self,
        message: WebSocketMessage,
    ) -> impl Future<Output = Result<Option<WebSocketMessage>>> + Send;
    fn on_close(
        &self,
        code: Option<WebSocketCloseCode>,
    ) -> impl Future<Output = ()> + Send;
}
Expand description

WebSocket connection handler

Required Methods§

Source

fn on_connect(&self) -> impl Future<Output = ()> + Send

Handle a new WebSocket connection

Source

fn on_message( &self, message: WebSocketMessage, ) -> impl Future<Output = Result<Option<WebSocketMessage>>> + Send

Handle an incoming message

Source

fn on_close( &self, code: Option<WebSocketCloseCode>, ) -> impl Future<Output = ()> + Send

Handle connection close

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§