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§
Provided Methods§
Sourcefn on_close(
&mut self,
code: CloseCode,
reason: &str,
) -> impl Future<Output = RetryStrategy> + Send
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.
Sourcefn on_connect(&mut self) -> impl Future<Output = ()> + Send
fn on_connect(&mut self) -> impl Future<Output = ()> + Send
Defines a callback for when connection succeeds.
Sourcefn on_connect_failure(&mut self) -> impl Future<Output = RetryStrategy> + Send
fn on_connect_failure(&mut self) -> impl Future<Output = RetryStrategy> + Send
Defines the behavior for when the connection fails.
Return the RetryStrategy to use.
Sourcefn on_disconnect(&mut self) -> impl Future<Output = RetryStrategy> + Send
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.