pub struct WebSocketAdapter { /* private fields */ }Expand description
WebSocket 适配器
提供高级 WebSocket 连接管理,包括:
- 自动连接和重连
- 消息流式接收
- 线程安全的发送
Implementations§
Source§impl WebSocketAdapter
impl WebSocketAdapter
Sourcepub fn with_config(url: impl Into<String>, config: WebSocketConfig) -> Self
pub fn with_config(url: impl Into<String>, config: WebSocketConfig) -> Self
创建带配置的 WebSocket 适配器
Sourcepub async fn state(&self) -> ConnectionState
pub async fn state(&self) -> ConnectionState
获取连接状态
Sourcepub fn abort_flag(&self) -> Arc<AtomicBool>
pub fn abort_flag(&self) -> Arc<AtomicBool>
获取中断标志
Sourcepub async fn connect(
&self,
) -> Result<WebSocketStream<MaybeTlsStream<TcpStream>>>
pub async fn connect( &self, ) -> Result<WebSocketStream<MaybeTlsStream<TcpStream>>>
建立 WebSocket 连接
返回消息接收流
Sourcepub async fn send(&self, message: WebSocketMessage) -> Result<()>
pub async fn send(&self, message: WebSocketMessage) -> Result<()>
发送消息
Sourcepub async fn create_stream(&self) -> Result<WebSocketMessageStream>
pub async fn create_stream(&self) -> Result<WebSocketMessageStream>
创建消息流
连接 WebSocket 并返回消息接收流
Auto Trait Implementations§
impl !RefUnwindSafe for WebSocketAdapter
impl !UnwindSafe for WebSocketAdapter
impl Freeze for WebSocketAdapter
impl Send for WebSocketAdapter
impl Sync for WebSocketAdapter
impl Unpin for WebSocketAdapter
impl UnsafeUnpin for WebSocketAdapter
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