pub struct ServerWrapper { /* private fields */ }Expand description
服务端包装器
提供统一的 ServerHandle 访问接口,所有构建模式都使用此包装器。
§设计原则
- 统一接口:所有模式(简单、观察者、Flare)都通过
ServerWrapper访问服务端功能 - 共享底层:基于
HybridServer,共享所有核心能力 - 类型安全:通过 Rust 类型系统保证接口的正确性
Implementations§
Source§impl ServerWrapper
impl ServerWrapper
Sourcepub fn new(server: HybridServer) -> Self
pub fn new(server: HybridServer) -> Self
创建新的服务端包装器
Sourcepub fn get_server_handle_components(
&self,
) -> Option<Arc<dyn ConnectionManagerTrait>>
pub fn get_server_handle_components( &self, ) -> Option<Arc<dyn ConnectionManagerTrait>>
获取 ServerHandle 组件(用于创建 DefaultServerHandle)
§返回
返回 ConnectionManagerTrait,如果 ServerCore 未初始化则返回 None
Sourcepub fn get_server_handle(&self) -> Option<Arc<dyn ServerHandle>>
pub fn get_server_handle(&self) -> Option<Arc<dyn ServerHandle>>
获取 ServerHandle(直接使用 HybridServer 作为 ServerHandle)
§返回
返回 ServerHandle trait object,如果 ServerCore 未初始化则返回 None
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
检查服务器是否运行
Sourcepub fn connection_count(&self) -> usize
pub fn connection_count(&self) -> usize
获取连接数量
Sourcepub fn user_count(&self) -> usize
pub fn user_count(&self) -> usize
获取用户数量
Sourcepub async fn broadcast_except(
&self,
frame: &Frame,
exclude_connection_id: &str,
) -> Result<()>
pub async fn broadcast_except( &self, frame: &Frame, exclude_connection_id: &str, ) -> Result<()>
广播消息到所有连接,排除指定连接
Sourcepub async fn disconnect(&self, connection_id: &str) -> Result<()>
pub async fn disconnect(&self, connection_id: &str) -> Result<()>
断开指定连接
Sourcepub fn protocols(&self) -> Vec<TransportProtocol>
pub fn protocols(&self) -> Vec<TransportProtocol>
获取协议列表
Auto Trait Implementations§
impl !RefUnwindSafe for ServerWrapper
impl !UnwindSafe for ServerWrapper
impl Freeze for ServerWrapper
impl Send for ServerWrapper
impl Sync for ServerWrapper
impl Unpin for ServerWrapper
impl UnsafeUnpin for ServerWrapper
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more