pub struct WebSocket { /* private fields */ }Expand description
Represents a WebSocket client connection.
This struct manages the WebSocket lifecycle including:
- Connection state
- Message sending/receiving
- Configuration
Implementations§
Source§impl WebSocket
impl WebSocket
Sourcepub fn send_text(&mut self, text: &str) -> WebSocketResult
pub fn send_text(&mut self, text: &str) -> WebSocketResult
Sourcepub fn send_binary(&mut self, data: &[u8]) -> WebSocketResult
pub fn send_binary(&mut self, data: &[u8]) -> WebSocketResult
Sourcepub fn send_ping(&mut self, data: &[u8]) -> WebSocketResult
pub fn send_ping(&mut self, data: &[u8]) -> WebSocketResult
Sourcepub fn send_pong(&mut self, data: &[u8]) -> WebSocketResult
pub fn send_pong(&mut self, data: &[u8]) -> WebSocketResult
Sourcepub fn receive(&mut self) -> WebSocketMessageResult
pub fn receive(&mut self) -> WebSocketMessageResult
Receives a message synchronously.
§Returns
WebSocketMessageResult- Result containing the received message or error.
Sourcepub fn close(&mut self) -> WebSocketResult
pub fn close(&mut self) -> WebSocketResult
Closes the WebSocket connection synchronously.
§Returns
WebSocketResult- Result indicating success or failure.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Sourcepub async fn send_text_async(&mut self, text: &str) -> WebSocketResult
pub async fn send_text_async(&mut self, text: &str) -> WebSocketResult
Sourcepub async fn send_binary_async(&mut self, data: &[u8]) -> WebSocketResult
pub async fn send_binary_async(&mut self, data: &[u8]) -> WebSocketResult
Sourcepub async fn send_ping_async(&mut self, data: &[u8]) -> WebSocketResult
pub async fn send_ping_async(&mut self, data: &[u8]) -> WebSocketResult
Sourcepub async fn send_pong_async(&mut self, data: &[u8]) -> WebSocketResult
pub async fn send_pong_async(&mut self, data: &[u8]) -> WebSocketResult
Sourcepub async fn receive_async(&mut self) -> WebSocketMessageResult
pub async fn receive_async(&mut self) -> WebSocketMessageResult
Receives a message asynchronously.
§Returns
WebSocketMessageResult- Result containing the received message or error.
Sourcepub async fn close_async_method(&mut self) -> WebSocketResult
pub async fn close_async_method(&mut self) -> WebSocketResult
Closes the WebSocket connection asynchronously.
§Returns
WebSocketResult- Result indicating success or failure.
Trait Implementations§
Source§impl AsyncWebSocketTrait for WebSocket
Asynchronous WebSocket trait implementation.
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
Source§fn 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>>
Sends a text message asynchronously. Read more
Source§fn 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>>
Sends a binary message asynchronously. Read more
Source§fn 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>>
Sends a ping message asynchronously. Read more
Source§fn 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>>
Sends a pong message asynchronously. Read more
Source§fn receive(
&mut self,
) -> Pin<Box<dyn Future<Output = WebSocketMessageResult> + Send + '_>>
fn receive( &mut self, ) -> Pin<Box<dyn Future<Output = WebSocketMessageResult> + Send + '_>>
Receives a message asynchronously. Read more
Source§fn close(
&mut self,
) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + '_>>
fn close( &mut self, ) -> Pin<Box<dyn Future<Output = WebSocketResult> + Send + '_>>
Closes the WebSocket connection asynchronously. Read more
Source§fn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Checks if the WebSocket is currently connected. Read more
Source§impl Clone for WebSocket
Clone implementation for WebSocket.
impl Clone for WebSocket
Clone implementation for WebSocket.
Creates a new WebSocket instance with cloned configuration but resets:
- Connection status to false
- Connection to None
Source§impl Default for WebSocket
Default implementation for WebSocket.
impl Default for WebSocket
Default implementation for WebSocket.
Creates a WebSocket with:
- Empty URL
- Empty headers
- Default configuration
- Disconnected state
- No active connection
Source§impl WebSocketTrait for WebSocket
Synchronous WebSocket trait implementation.
impl WebSocketTrait for WebSocket
Synchronous WebSocket trait implementation.
Provides synchronous methods for WebSocket operations including:
- Sending messages (text, binary, ping, pong)
- Receiving messages
- Closing connections
- Checking connection status
Source§fn send_text(&mut self, text: &str) -> WebSocketResult
fn send_text(&mut self, text: &str) -> WebSocketResult
Sends a text message synchronously. Read more
Source§fn send_binary(&mut self, data: &[u8]) -> WebSocketResult
fn send_binary(&mut self, data: &[u8]) -> WebSocketResult
Sends a binary message synchronously. Read more
Source§fn send_ping(&mut self, data: &[u8]) -> WebSocketResult
fn send_ping(&mut self, data: &[u8]) -> WebSocketResult
Sends a ping message synchronously. Read more
Source§fn send_pong(&mut self, data: &[u8]) -> WebSocketResult
fn send_pong(&mut self, data: &[u8]) -> WebSocketResult
Sends a pong message synchronously. Read more
Source§fn receive(&mut self) -> WebSocketMessageResult
fn receive(&mut self) -> WebSocketMessageResult
Receives a message synchronously. Read more
Source§fn close(&mut self) -> WebSocketResult
fn close(&mut self) -> WebSocketResult
Closes the WebSocket connection synchronously. Read more
Source§fn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Checks if the WebSocket is currently connected. Read more
Auto Trait Implementations§
impl Freeze for WebSocket
impl !RefUnwindSafe for WebSocket
impl Send for WebSocket
impl Sync for WebSocket
impl Unpin for WebSocket
impl UnsafeUnpin for WebSocket
impl !UnwindSafe for WebSocket
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