Trait MessageHandler

Source
pub trait MessageHandler: Send + Sync {
    // Required method
    fn on_message<'life0, 'async_trait>(
        &'life0 mut self,
        message: Message,
    ) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn on_connected<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_disconnected<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_error<'life0, 'async_trait>(
        &'life0 mut self,
        error: WebSocketError,
    ) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn set_sender(&mut self, _sender: UnboundedSender<Message>) { ... }
    fn send_message(&self, _message: Message) -> WebSocketResult<()> { ... }
}
Expand description

Message handler trait

Required Methods§

Source

fn on_message<'life0, 'async_trait>( &'life0 mut self, message: Message, ) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a received message

Provided Methods§

Source

fn on_connected<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle connection established

Source

fn on_disconnected<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle connection closed

Source

fn on_error<'life0, 'async_trait>( &'life0 mut self, error: WebSocketError, ) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle errors

Source

fn set_sender(&mut self, _sender: UnboundedSender<Message>)

Set the sender for outgoing messages (optional, default implementation does nothing)

Source

fn send_message(&self, _message: Message) -> WebSocketResult<()>

Send a message through the WebSocket (optional, default implementation returns error)

Implementors§