Skip to main content

WebSocket

Struct WebSocket 

Source
pub struct WebSocket { /* private fields */ }
Expand description

An open WebSocket. Read it with WebSocket::next or WebSocket::read_async, and send through it or a WsSender. Dropping it closes the connection with code 1000.

Implementations§

Source§

impl WebSocket

Source

pub fn protocol(&self) -> Option<String>

The subprotocol the server chose.

Source

pub fn sender(&self) -> WsSender

A sending half to give to other code: it can send, ping and close.

Source

pub fn send_async( &self, message: Message, done: impl FnOnce(Result<(), HttpError>) + Send + 'static, )

Send a message; done reports when the platform took it.

Source

pub fn send_future(&self, message: Message) -> Oneshot<Result<(), HttpError>> ⓘ

Send a message and await the platform taking it.

Source

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

Close with code and reason.

Source

pub fn next(&mut self) -> NextMessage<'_> ⓘ

The next message; the last is a Message::Close, then None.

Source

pub fn read_async( self, on_message: impl FnMut(Option<Result<Message, HttpError>>) -> bool + Send + 'static, )

Hand each message to on_message as it arrives, then None at the end or Some(Err) on failure. Returning false closes the connection.

Trait Implementations§

Source§

impl Debug for WebSocket

Source§

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

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

impl Drop for WebSocket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.