Trait Connection

Source
pub trait Connection {
    // Required methods
    fn receive(&mut self) -> impl Future<Output = Option<Message>> + Send;
    fn send(
        &mut self,
        message: Message,
    ) -> impl Future<Output = Result<(), Error>> + Send;
}
Expand description

Abstraction around a websocket connection.

Built in implementations are provided for ws_stream_wasm & async_tungstenite.

If users wish to add support for a new client they should implement this trait.

Required Methods§

Source

fn receive(&mut self) -> impl Future<Output = Option<Message>> + Send

Receive the next message on this connection.

Source

fn send( &mut self, message: Message, ) -> impl Future<Output = Result<(), Error>> + Send

Send a message with on connection

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Connection for Connection

Available on crate feature ws_stream_wasm only.
Source§

impl<T> Connection for T
where T: Stream<Item = Result<Message, Error>> + Sink<Message> + Send + Sync + Unpin, <T as Sink<Message>>::Error: Display,

Available on crate feature tungstenite only.