pub trait ServerHandle: Send + Sync {
// Required methods
fn send_to<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
frame: &'life2 Frame,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn send_to_user<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
frame: &'life2 Frame,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn broadcast<'life0, 'life1, 'async_trait>(
&'life0 self,
frame: &'life1 Frame,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn broadcast_except<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
frame: &'life1 Frame,
exclude_connection_id: &'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 disconnect<'life0, 'life1, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn connection_count(&self) -> usize;
fn user_count(&self) -> usize;
// Provided method
fn send_to_connections<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
connection_ids: &'life1 [String],
frame: &'life2 Frame,
) -> Pin<Box<dyn Future<Output = (i32, i32)> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
}Expand description
服务器操作处理器
提供消息发送和连接管理的轻量级接口 可以在任何需要发送消息或管理连接的地方注入此 trait,而不需要注入整个 Server
§示例
use flare_core::server::ServerHandle;
use flare_core::common::error::Result;
use flare_core::common::protocol::Frame;
use std::sync::Arc;
struct MyHandler {
server_handle: Arc<dyn ServerHandle>,
}
impl MyHandler {
async fn send_message(&self, connection_id: &str, frame: &Frame) -> Result<()> {
self.server_handle.send_to(connection_id, frame).await
}
}Required Methods§
Sourcefn send_to<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
frame: &'life2 Frame,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn send_to<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
frame: &'life2 Frame,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn send_to_user<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
frame: &'life2 Frame,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn send_to_user<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
frame: &'life2 Frame,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn broadcast<'life0, 'life1, 'async_trait>(
&'life0 self,
frame: &'life1 Frame,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn broadcast<'life0, 'life1, 'async_trait>(
&'life0 self,
frame: &'life1 Frame,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn broadcast_except<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
frame: &'life1 Frame,
exclude_connection_id: &'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 broadcast_except<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
frame: &'life1 Frame,
exclude_connection_id: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn disconnect<'life0, 'life1, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn disconnect<'life0, 'life1, 'async_trait>(
&'life0 self,
connection_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn connection_count(&self) -> usize
fn connection_count(&self) -> usize
Sourcefn user_count(&self) -> usize
fn user_count(&self) -> usize
Provided Methods§
Sourcefn send_to_connections<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
connection_ids: &'life1 [String],
frame: &'life2 Frame,
) -> Pin<Box<dyn Future<Output = (i32, i32)> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn send_to_connections<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
connection_ids: &'life1 [String],
frame: &'life2 Frame,
) -> Pin<Box<dyn Future<Output = (i32, i32)> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
同一 Frame 发送到多个连接(群扇出主路径)。 默认逐连接;带连接管理器的实现按(序列化格式, 压缩)分组、 每组序列化一次共享给组内无加密连接。返回(成功数, 失败数)。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl ServerHandle for DefaultServerHandle
impl ServerHandle for HybridServer
让 HybridServer 实现 ServerHandle trait 这样可以在任何需要发送消息的地方注入 HybridServer 的 ServerCore,而不需要整个 Server
impl ServerHandle for ServerCore
让 ServerCore 实现 ServerHandle trait 这样可以在任何需要发送消息的地方注入 ServerCore,而不需要整个 Server