Pass owned error to websocket client on_error
This change passes the error as owned, instead of a reference. It allows
the web socket client user greater flexibility with what they can do
with the error.
As the error isn't used by the websocket, this has no additional effects
internally.
@@ -74,7 +74,7 @@ use tokio::prelude::*;
use crate::events::{Igniter, ParseError, WebSocketError};
type OnErrorHandle<T> =
- dyn Fn(&WebSocketError, Context<T>) -> Result<(), WebSocketError> + Send + Sync + 'static;
+ dyn Fn(WebSocketError, Context<T>) -> Result<(), WebSocketError> + Send + Sync + 'static;
const MAX_FRAME_SIZE: usize = 10_000_000;
const DEFAULT_RECONNECT: bool = false;
@@ -241,7 +241,7 @@ impl<T: ParseBytes<T> + 'static> WebSocketClient<T> {
/// Websocket or to reestablish the connection if appropriate.
pub fn on_error<F>(&mut self, on_error: F)
where
- F: Fn(&WebSocketError, Context<T>) -> Result<(), WebSocketError> + Send + Sync + 'static,
+ F: Fn(WebSocketError, Context<T>) -> Result<(), WebSocketError> + Send + Sync + 'static,
{
self.on_error = Some(Arc::new(on_error));
}
@@ -307,7 +307,7 @@ impl<T: ParseBytes<T> + 'static> WebSocketClient<T> {
if res.status() != StatusCode::SWITCHING_PROTOCOLS {
error!("The server didn't upgrade: {}", res.status());
if let Err(err) = on_error(
- &WebSocketError::ConnectError(format!(
+ WebSocketError::ConnectError(format!(
"Received status code {:?} while attempting to establish a connection"
, res.status())),
connection_failed_context,
@@ -610,7 +610,7 @@ impl<T: ParseBytes<T> + 'static> Context<T> {
self.reset_wait();
self.reset_reconnect_count();
- on_error(&error_message, self.clone())
+ on_error(error_message, self.clone())
}
}
