Skip to main content

WebSocket

Struct WebSocket 

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

Implementations§

Source§

impl WebSocket

Source

pub fn new(upgraded: Upgraded, config: WebSocketConfig) -> WebSocket

Take over a connection the HTTP server has finished with.

Source

pub fn on_path(self, path: impl Into<String>) -> Self

Label the socket for instrumentation with the route it was opened on.

Source

pub fn with_protocol(self, protocol: Option<String>) -> Self

Source

pub fn sender(&self) -> Sender

A handle other tasks can push messages through.

Source

pub fn path(&self) -> &str

Source

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

The subprotocol agreed during the handshake, if any.

Source

pub fn is_closed(&self) -> bool

Source

pub fn close_frame(&self) -> Option<&CloseFrame>

How the connection ended, once it has. Available after recv returns None, which is where an application usually wants to log it.

Source

pub fn received(&self) -> u64

How many data messages have arrived.

Source

pub async fn send(&mut self, message: impl Into<Message>) -> WsResult<()>

Source

pub async fn recv(&mut self) -> Option<Message>

The next message from the peer, or None once the connection is over.

Only Text and Binary come out of here. Pings, pongs and closes are answered internally, because every application would have to write the same three replies and one of them would get it wrong.

Source

pub async fn close(&mut self, code: CloseCode, reason: impl Into<String>)

Close the connection politely: send a close frame, then wait — briefly — for the peer’s.

Trait Implementations§

Source§

impl Drop for WebSocket

Dispatched here so every socket reports exactly once, however it ended — including the ones an application drops without draining.

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.