Skip to main content

WebSocketConnection

Trait WebSocketConnection 

Source
pub trait WebSocketConnection: WasmCompatSend + WasmCompatSync {
    // Required methods
    fn send(
        &mut self,
        frame: Frame,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>;
    fn recv(
        &mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>, Error>> + Send + '_>>;
    fn close(
        &mut self,
        frame: Option<CloseFrame>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>;
}
Available on crate feature websocket only.
Expand description

One open websocket connection, usable as a trait object. Calls are sequential: sessions must not poll send and receive concurrently. WASM-compatible bounds preserve the containing session’s thread-safety contract.

Required Methods§

Source

fn send( &mut self, frame: Frame, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Write one frame.

Source

fn recv( &mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>, Error>> + Send + '_>>

Read the next frame; Ok(None) means the peer ended the stream.

Source

fn close( &mut self, frame: Option<CloseFrame>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Completes a close handshake. Callers must avoid repeated closes; backends may return an error for an already closed socket.

Trait Implementations§

Source§

impl WebSocketConnection for Box<dyn WebSocketConnection>

Source§

fn send( &mut self, frame: Frame, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Write one frame.
Source§

fn recv( &mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>, Error>> + Send + '_>>

Read the next frame; Ok(None) means the peer ended the stream.
Source§

fn close( &mut self, frame: Option<CloseFrame>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Completes a close handshake. Callers must avoid repeated closes; backends may return an error for an already closed socket.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl WebSocketConnection for Box<dyn WebSocketConnection>

Source§

fn send( &mut self, frame: Frame, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Source§

fn recv( &mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<Frame>, Error>> + Send + '_>>

Source§

fn close( &mut self, frame: Option<CloseFrame>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Implementors§