Skip to main content

AsyncWebSocketTrait

Trait AsyncWebSocketTrait 

Source
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§

Source

fn send_text<'a>( &'a mut self, text: &'a str, ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>

Sends a text message asynchronously.

§Arguments
  • &str - The text message to send.
§Returns
  • WebSocketResult - Result indicating success or failure.
Source

fn send_binary<'a>( &'a mut self, data: &'a [u8], ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>

Sends a binary message asynchronously.

§Arguments
  • &[u8] - The binary data to send.
§Returns
  • WebSocketResult - Result indicating success or failure.
Source

fn send_ping<'a>( &'a mut self, data: &'a [u8], ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>

Sends a ping message asynchronously.

§Arguments
  • &[u8] - The ping data to send.
§Returns
  • WebSocketResult - Result indicating success or failure.
Source

fn send_pong<'a>( &'a mut self, data: &'a [u8], ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + 'a>>

Sends a pong message asynchronously.

§Arguments
  • &[u8] - The pong data to send.
§Returns
  • WebSocketResult - Result indicating success or failure.
Source

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.
Source

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.
Source

fn is_connected(&self) -> bool

Checks if the WebSocket is currently connected.

§Returns
  • bool - True if connected, false otherwise.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

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