pub trait AsyncWebSocketTrait: Send + Sync {
// Required methods
fn send_text<'a>(
&'a mut self,
text: &'a str,
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>;
fn send_binary<'a>(
&'a mut self,
data: &'a [u8],
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>;
fn send_ping<'a>(
&'a mut self,
data: &'a [u8],
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>;
fn send_pong<'a>(
&'a mut self,
data: &'a [u8],
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>;
fn receive<'a>(
&'a mut self,
) -> Pin<Box<dyn Future<Output = WebSocketMessageResult> + Send + 'a>>;
fn close<'a>(
&'a mut self,
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>;
fn is_connected(&self) -> bool;
}Expand description
Asynchronous WebSocket operations trait.
Defines the interface for asynchronous WebSocket operations including:
- Sending messages (text, binary, ping, pong)
- Receiving messages
- Closing connections
- Checking connection status
Required Methods§
Sourcefn send_text<'a>(
&'a mut self,
text: &'a str,
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>
fn send_text<'a>( &'a mut self, text: &'a str, ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>
Sourcefn send_binary<'a>(
&'a mut self,
data: &'a [u8],
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>
fn send_binary<'a>( &'a mut self, data: &'a [u8], ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>
Sourcefn send_ping<'a>(
&'a mut self,
data: &'a [u8],
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>
fn send_ping<'a>( &'a mut self, data: &'a [u8], ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>
Sourcefn send_pong<'a>(
&'a mut self,
data: &'a [u8],
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>
fn send_pong<'a>( &'a mut self, data: &'a [u8], ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>
Sourcefn receive<'a>(
&'a mut self,
) -> Pin<Box<dyn Future<Output = WebSocketMessageResult> + Send + 'a>>
fn receive<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = WebSocketMessageResult> + Send + 'a>>
Receives a message asynchronously.
§Returns
WebSocketMessageResult- Result containing the received message or error.
Sourcefn close<'a>(
&'a mut self,
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>
fn close<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>
Closes the WebSocket connection asynchronously.
§Returns
WebSocketResult- Result indicating success or failure.
Sourcefn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl AsyncWebSocketTrait for WebSocket
Asynchronous WebSocket trait implementation.
Provides asynchronous methods for WebSocket operations including:
- Sending messages (text, binary, ping, pong)
- Receiving messages
- Closing connections
- Checking connection status