pub struct MemoryGatewayTransport { /* private fields */ }Expand description
内存 Gateway 传输实现 — 用于测试和开发环境
不进行实际网络通信,所有状态保存在内存中,供测试断言使用。
§数据结构
client_messages: client_id → messages 队列(键存在即表示 client 在线)client_groups: client_id → groups 映射group_clients: group → client_ids 映射
§线程安全
通过 Arc<Mutex<GatewayState>> 保护,支持并发访问。所有操作在单个锁内完成,
保证多字段状态的一致性。
§用法
ⓘ
use sz_rust_auth_facade::gateway::{MemoryGatewayTransport, GatewayTransport};
let transport = MemoryGatewayTransport::new();
transport.register_client("7f00000108fc00000001");
transport.send_to_client("7f00000108fc00000001", "hello").unwrap();
assert_eq!(transport.client_messages("7f00000108fc00000001"), vec!["hello".to_string()]);Implementations§
Source§impl MemoryGatewayTransport
impl MemoryGatewayTransport
Sourcepub fn new() -> MemoryGatewayTransport
pub fn new() -> MemoryGatewayTransport
创建新的内存传输
Sourcepub fn register_client(&self, client_id: &str)
pub fn register_client(&self, client_id: &str)
注册客户端(标记为在线)
非 trait 方法,供测试/开发注册在线客户端。对齐 PHP GatewayWorker 中客户端连接 建立后自动上线的行为。重复注册为幂等操作。
§参数
client_id: 客户端 ID
Trait Implementations§
Source§impl Debug for MemoryGatewayTransport
impl Debug for MemoryGatewayTransport
Source§impl Default for MemoryGatewayTransport
impl Default for MemoryGatewayTransport
Source§fn default() -> MemoryGatewayTransport
fn default() -> MemoryGatewayTransport
Returns the “default value” for a type. Read more
Source§impl GatewayTransport for MemoryGatewayTransport
impl GatewayTransport for MemoryGatewayTransport
Source§fn send_to_client(
&self,
client_id: &str,
message: &str,
) -> Result<(), GatewayError>
fn send_to_client( &self, client_id: &str, message: &str, ) -> Result<(), GatewayError>
向指定 client_id 发送消息 Read more
Source§fn send_to_clients(
&self,
client_ids: &[String],
message: &str,
) -> Result<(), GatewayError>
fn send_to_clients( &self, client_ids: &[String], message: &str, ) -> Result<(), GatewayError>
向多个 client_id 发送消息 Read more
Source§fn send_to_all(&self, message: &str) -> Result<(), GatewayError>
fn send_to_all(&self, message: &str) -> Result<(), GatewayError>
向所有在线 client_id 发送广播 Read more
Source§fn send_to_group(&self, group: &str, message: &str) -> Result<(), GatewayError>
fn send_to_group(&self, group: &str, message: &str) -> Result<(), GatewayError>
向指定群组发送消息 Read more
Source§fn get_all_client_ids(&self) -> Result<Vec<String>, GatewayError>
fn get_all_client_ids(&self) -> Result<Vec<String>, GatewayError>
获取所有在线 client_id
Source§fn get_client_id_list_by_group(
&self,
group: &str,
) -> Result<Vec<String>, GatewayError>
fn get_client_id_list_by_group( &self, group: &str, ) -> Result<Vec<String>, GatewayError>
获取指定群组中的 client_id Read more
Source§fn get_groups_by_client_id(
&self,
client_id: &str,
) -> Result<Vec<String>, GatewayError>
fn get_groups_by_client_id( &self, client_id: &str, ) -> Result<Vec<String>, GatewayError>
获取 client_id 所在的群组 Read more
Source§fn join_group(&self, client_id: &str, group: &str) -> Result<(), GatewayError>
fn join_group(&self, client_id: &str, group: &str) -> Result<(), GatewayError>
将 client_id 加入群组 Read more
Source§fn leave_group(&self, client_id: &str, group: &str) -> Result<(), GatewayError>
fn leave_group(&self, client_id: &str, group: &str) -> Result<(), GatewayError>
将 client_id 离开群组 Read more
Source§fn ungroup(&self, group: &str) -> Result<(), GatewayError>
fn ungroup(&self, group: &str) -> Result<(), GatewayError>
解散指定群组(对齐 PHP
Gateway::ungroup()) Read moreSource§fn get_client_count(&self) -> Result<usize, GatewayError>
fn get_client_count(&self) -> Result<usize, GatewayError>
获取在线 client_id 数量
Source§fn get_client_count_by_group(&self, group: &str) -> Result<usize, GatewayError>
fn get_client_count_by_group(&self, group: &str) -> Result<usize, GatewayError>
获取指定群组的在线 client_id 数量 Read more
Source§fn close_client(&self, client_id: &str) -> Result<(), GatewayError>
fn close_client(&self, client_id: &str) -> Result<(), GatewayError>
关闭指定 client_id 的连接 Read more
Auto Trait Implementations§
impl !Freeze for MemoryGatewayTransport
impl !RefUnwindSafe for MemoryGatewayTransport
impl Send for MemoryGatewayTransport
impl Sync for MemoryGatewayTransport
impl Unpin for MemoryGatewayTransport
impl UnsafeUnpin for MemoryGatewayTransport
impl UnwindSafe for MemoryGatewayTransport
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.