Skip to main content

WebSocketConnection

Struct WebSocketConnection 

Source
pub struct WebSocketConnection {
    pub id: String,
    pub url: String,
    pub state: WebSocketState,
    pub close_code: Option<u16>,
    pub close_reason: Option<String>,
    /* private fields */
}
Expand description

A tracked WebSocket connection

Fields§

§id: String

Connection ID

§url: String

WebSocket URL

§state: WebSocketState

Connection state

§close_code: Option<u16>

Close code (if closed)

§close_reason: Option<String>

Close reason (if closed)

Implementations§

Source§

impl WebSocketConnection

Source

pub fn new(id: &str, url: &str) -> Self

Create a new connection

Source

pub fn open(&mut self)

Open the connection

Source

pub fn close(&mut self, code: u16, reason: &str)

Close the connection

Source

pub fn elapsed_ms(&self) -> u64

Get elapsed time in milliseconds

Source

pub fn record_message(&self, message: WebSocketMessage)

Record a message

Source

pub fn send_text(&self, data: &str)

Send a text message

Source

pub fn send_binary(&self, data: Vec<u8>)

Send a binary message

Source

pub fn receive_text(&self, data: &str)

Receive a text message

Source

pub fn receive_binary(&self, data: Vec<u8>)

Receive a binary message

Source

pub fn messages(&self) -> Vec<WebSocketMessage>

Get all messages

Source

pub fn sent_messages(&self) -> Vec<WebSocketMessage>

Get sent messages

Source

pub fn received_messages(&self) -> Vec<WebSocketMessage>

Get received messages

Source

pub fn message_count(&self) -> usize

Get message count

Source

pub const fn is_open(&self) -> bool

Check if connection is open

Source

pub const fn is_closed(&self) -> bool

Check if connection is closed

Trait Implementations§

Source§

impl Debug for WebSocketConnection

Source§

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

Formats the value using the given formatter. 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> 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, 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.