Skip to main content

WebSocket

Struct WebSocket 

Source
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

Source

pub fn send_text(&mut self, text: &str) -> WebSocketResult

Sends a text message synchronously.

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

pub fn send_binary(&mut self, data: &[u8]) -> WebSocketResult

Sends a binary message synchronously.

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

pub fn send_ping(&mut self, data: &[u8]) -> WebSocketResult

Sends a ping message synchronously.

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

pub fn send_pong(&mut self, data: &[u8]) -> WebSocketResult

Sends a pong message synchronously.

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

pub fn receive(&mut self) -> WebSocketMessageResult

Receives a message synchronously.

§Returns
  • WebSocketMessageResult - Result containing the received message or error.
Source

pub fn close(&mut self) -> WebSocketResult

Closes the WebSocket connection synchronously.

§Returns
  • WebSocketResult - Result indicating success or failure.
Source

pub fn is_connected(&self) -> bool

Checks if the WebSocket is currently connected.

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

pub async fn send_text_async(&mut self, text: &str) -> WebSocketResult

Sends a text message asynchronously.

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

pub async fn send_binary_async(&mut self, data: &[u8]) -> WebSocketResult

Sends a binary message asynchronously.

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

pub async fn send_ping_async(&mut self, data: &[u8]) -> WebSocketResult

Sends a ping message asynchronously.

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

pub async fn send_pong_async(&mut self, data: &[u8]) -> WebSocketResult

Sends a pong message asynchronously.

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

pub async fn receive_async(&mut self) -> WebSocketMessageResult

Receives a message asynchronously.

§Returns
  • WebSocketMessageResult - Result containing the received message or error.
Source

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.

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

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

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

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

Sends a pong message asynchronously. Read more
Source§

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 + '_>>

Closes the WebSocket connection asynchronously. Read more
Source§

fn is_connected(&self) -> bool

Checks if the WebSocket is currently connected. Read more
Source§

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§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WebSocket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WebSocket

Default implementation for WebSocket.

Creates a WebSocket with:

  • Empty URL
  • Empty headers
  • Default configuration
  • Disconnected state
  • No active connection
Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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

Sends a text message synchronously. Read more
Source§

fn send_binary(&mut self, data: &[u8]) -> WebSocketResult

Sends a binary message synchronously. Read more
Source§

fn send_ping(&mut self, data: &[u8]) -> WebSocketResult

Sends a ping message synchronously. Read more
Source§

fn send_pong(&mut self, data: &[u8]) -> WebSocketResult

Sends a pong message synchronously. Read more
Source§

fn receive(&mut self) -> WebSocketMessageResult

Receives a message synchronously. Read more
Source§

fn close(&mut self) -> WebSocketResult

Closes the WebSocket connection synchronously. Read more
Source§

fn is_connected(&self) -> bool

Checks if the WebSocket is currently connected. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendClone for T
where T: Any + Send + Clone,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySendSyncClone for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> AnySyncClone for T
where T: Any + Sync + Clone,

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,