Handler

Trait Handler 

Source
pub trait Handler: Send {
    // Required methods
    fn on_text(&mut self, text: &str) -> impl Future<Output = ()> + Send;
    fn on_binary(&mut self, buffer: &[u8]) -> impl Future<Output = ()> + Send;

    // Provided methods
    fn on_close(
        &mut self,
        code: CloseCode,
        reason: &str,
    ) -> impl Future<Output = RetryStrategy> + Send { ... }
    fn on_connect(&mut self) -> impl Future<Output = ()> + Send { ... }
    fn on_connect_failure(
        &mut self,
    ) -> impl Future<Output = RetryStrategy> + Send { ... }
    fn on_disconnect(&mut self) -> impl Future<Output = RetryStrategy> + Send { ... }
}
Expand description

Defines how to handle text, binary and close messages from the server.

It also allows to define RetryStrategy when connection fails and a callback on connection.

Required Methods§

Source

fn on_text(&mut self, text: &str) -> impl Future<Output = ()> + Send

Handle text messages.

Any error will trigger a reconnection.

Source

fn on_binary(&mut self, buffer: &[u8]) -> impl Future<Output = ()> + Send

Handle binary messages.

Any error will trigger a reconnection.

Provided Methods§

Source

fn on_close( &mut self, code: CloseCode, reason: &str, ) -> impl Future<Output = RetryStrategy> + Send

Defines the behavior for when the server closes the connection.

Return the RetryStrategy to use.

Source

fn on_connect(&mut self) -> impl Future<Output = ()> + Send

Defines a callback for when connection succeeds.

Source

fn on_connect_failure(&mut self) -> impl Future<Output = RetryStrategy> + Send

Defines the behavior for when the connection fails.

Return the RetryStrategy to use.

Source

fn on_disconnect(&mut self) -> impl Future<Output = RetryStrategy> + Send

Defines a callback for when connection is broken.

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§