Skip to main content

ClientEventHandler

Trait ClientEventHandler 

Source
pub trait ClientEventHandler: Send + Sync {
    // Provided methods
    fn handle_system_command<'life0, 'life1, 'async_trait>(
        &'life0 self,
        command_type: SysType,
        frame: &'life1 Frame,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn handle_message_command<'life0, 'life1, 'async_trait>(
        &'life0 self,
        command_type: PayloadType,
        frame: &'life1 Frame,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn handle_notification_command<'life0, 'life1, 'async_trait>(
        &'life0 self,
        command_type: NotifType,
        frame: &'life1 Frame,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn handle_connection_event<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event: &'life1 ConnectionEvent,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

客户端事件处理器

允许用户实现自定义逻辑来处理不同类型的客户端事件和命令

所有方法都有默认实现,用户只需要实现需要的方法即可

Provided Methods§

Source

fn handle_system_command<'life0, 'life1, 'async_trait>( &'life0 self, command_type: SysType, frame: &'life1 Frame, ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

处理系统命令

§参数
  • command_type: 系统命令类型(CONNECT, CONNECT_ACK, PING, PONG, KICKED, ERROR, CLOSE)
  • frame: 完整的消息帧
§返回
  • Ok(Some(Frame)): 需要发送的回复消息(可选)
  • Ok(None): 不需要回复
  • Err: 处理失败
Source

fn handle_message_command<'life0, 'life1, 'async_trait>( &'life0 self, command_type: PayloadType, frame: &'life1 Frame, ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

处理载荷命令(MESSAGE/EVENT/ACK/DATA)

Source

fn handle_notification_command<'life0, 'life1, 'async_trait>( &'life0 self, command_type: NotifType, frame: &'life1 Frame, ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

处理通知命令

§参数
  • command_type: 通知命令类型
  • frame: 完整的消息帧
§返回
  • Ok(Some(Frame)): 需要发送的回复消息(可选)
  • Ok(None): 不需要回复
  • Err: 处理失败
Source

fn handle_connection_event<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 ConnectionEvent, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

处理连接事件

§参数
  • event: 连接事件(Connected, Disconnected, Error)
§返回
  • Ok(()): 处理成功
  • Err: 处理失败

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§