pub trait MessageObserver: Send + Sync {
// Provided methods
fn handle_frame<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
frame: &'life1 Frame,
connection_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn handle_system_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_sys_cmd: &'life1 SystemCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn handle_message_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_msg_cmd: &'life1 PayloadCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn handle_notification_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_notif_cmd: &'life1 NotificationCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn handle_custom_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_custom_cmd: &'life1 CustomCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn handle_connection_event<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_event: &'life1 ConnectionEvent,
_connection_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
}Expand description
消息观察者标准接口
这是消息处理的核心接口,定义了如何处理不同类型的消息和事件。 服务端和客户端都可以实现这个接口来自定义消息处理逻辑。
§设计原则
- 分层处理: 先处理系统命令,再处理业务命令
- 可扩展性: 支持自定义命令类型处理
- 响应式: 可以返回响应 Frame 用于请求-响应模式
Provided Methods§
Sourcefn handle_frame<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
frame: &'life1 Frame,
connection_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle_frame<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
frame: &'life1 Frame,
connection_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn handle_system_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_sys_cmd: &'life1 SystemCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn handle_system_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_sys_cmd: &'life1 SystemCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
处理系统命令
默认实现返回 None,子类可以重写此方法
Sourcefn handle_message_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_msg_cmd: &'life1 PayloadCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn handle_message_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_msg_cmd: &'life1 PayloadCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
处理消息命令
默认实现返回 None,子类可以重写此方法
Sourcefn handle_notification_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_notif_cmd: &'life1 NotificationCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn handle_notification_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_notif_cmd: &'life1 NotificationCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
处理通知命令
默认实现返回 None,子类可以重写此方法
Sourcefn handle_custom_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_custom_cmd: &'life1 CustomCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn handle_custom_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_custom_cmd: &'life1 CustomCommand,
_frame: &'life2 Frame,
_connection_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<Frame>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
处理自定义命令(如 SyncMessages、ListSessions 等)
默认实现返回 None,子类可以重写此方法
Sourcefn handle_connection_event<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_event: &'life1 ConnectionEvent,
_connection_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle_connection_event<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_event: &'life1 ConnectionEvent,
_connection_id: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
处理连接事件
当连接状态发生变化时调用
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".