pub enum WsEvent {
Connecting,
Connected,
Disconnected,
Reconnecting {
attempt: u32,
delay: Duration,
error: Option<String>,
},
ReconnectSuccess,
ReconnectFailed {
attempt: u32,
error: String,
is_permanent: bool,
},
ReconnectExhausted {
total_attempts: u32,
last_error: String,
},
SubscriptionRestored,
PermanentError {
error: String,
},
Shutdown,
}Expand description
WebSocket connection event types.
These events are emitted during the WebSocket connection lifecycle to notify listeners about state changes, reconnection attempts, and errors.
§Example
use ccxt_core::ws_client::WsEvent;
use std::time::Duration;
fn handle_event(event: WsEvent) {
match event {
WsEvent::Connecting => println!("Connecting..."),
WsEvent::Connected => println!("Connected!"),
WsEvent::Disconnected => println!("Disconnected"),
WsEvent::Reconnecting { attempt, delay, error } => {
println!("Reconnecting (attempt {}), delay: {:?}, error: {:?}",
attempt, delay, error);
}
WsEvent::ReconnectSuccess => println!("Reconnected successfully"),
WsEvent::ReconnectFailed { attempt, error, is_permanent } => {
println!("Reconnect failed (attempt {}): {}, permanent: {}",
attempt, error, is_permanent);
}
WsEvent::ReconnectExhausted { total_attempts, last_error } => {
println!("All {} reconnect attempts exhausted: {}",
total_attempts, last_error);
}
WsEvent::SubscriptionRestored => println!("Subscriptions restored"),
WsEvent::PermanentError { error } => {
println!("Permanent error (no retry): {}", error);
}
WsEvent::Shutdown => println!("Shutdown complete"),
}
}Variants§
Connecting
Connection attempt started.
Emitted when the client begins establishing a WebSocket connection.
Connected
Connection established successfully.
Emitted when the WebSocket handshake completes and the connection is ready.
Disconnected
Connection closed.
Emitted when the WebSocket connection is closed, either gracefully or due to an error.
Reconnecting
Reconnection in progress.
Emitted before each reconnection attempt with details about the attempt.
Fields
ReconnectSuccess
Reconnection succeeded.
Emitted when a reconnection attempt successfully establishes a new connection.
ReconnectFailed
Single reconnection attempt failed.
Emitted when a reconnection attempt fails. More attempts may follow
unless is_permanent is true or max attempts is reached.
Fields
ReconnectExhausted
All reconnection attempts exhausted.
Emitted when the maximum number of reconnection attempts has been reached without successfully reconnecting. No further automatic reconnection will occur.
Fields
SubscriptionRestored
Subscriptions restored after reconnection.
Emitted after a successful reconnection when all previous subscriptions have been re-established.
PermanentError
Permanent error occurred (no retry).
Emitted when a permanent error is encountered that cannot be recovered through retries (e.g., authentication failure, invalid credentials).
Shutdown
Shutdown completed.
Emitted when the WebSocket client has completed its graceful shutdown process, including cancelling pending operations and closing connections.
Implementations§
Source§impl WsEvent
impl WsEvent
Sourcepub fn is_connecting(&self) -> bool
pub fn is_connecting(&self) -> bool
Returns true if this is a Connecting event.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true if this is a Connected event.
Sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Returns true if this is a Disconnected event.
Sourcepub fn is_reconnecting(&self) -> bool
pub fn is_reconnecting(&self) -> bool
Returns true if this is a Reconnecting event.
Sourcepub fn is_reconnect_success(&self) -> bool
pub fn is_reconnect_success(&self) -> bool
Returns true if this is a ReconnectSuccess event.
Sourcepub fn is_reconnect_failed(&self) -> bool
pub fn is_reconnect_failed(&self) -> bool
Returns true if this is a ReconnectFailed event.
Sourcepub fn is_reconnect_exhausted(&self) -> bool
pub fn is_reconnect_exhausted(&self) -> bool
Returns true if this is a ReconnectExhausted event.
Sourcepub fn is_subscription_restored(&self) -> bool
pub fn is_subscription_restored(&self) -> bool
Returns true if this is a SubscriptionRestored event.
Sourcepub fn is_permanent_error(&self) -> bool
pub fn is_permanent_error(&self) -> bool
Returns true if this is a PermanentError event.
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Returns true if this is a Shutdown event.
Sourcepub fn is_error(&self) -> bool
pub fn is_error(&self) -> bool
Returns true if this event indicates an error condition.
This includes ReconnectFailed, ReconnectExhausted, and PermanentError.
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Returns true if this event indicates a terminal state.
Terminal states are those where no further automatic recovery will occur:
ReconnectExhausted, PermanentError, and Shutdown.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WsEvent
impl RefUnwindSafe for WsEvent
impl Send for WsEvent
impl Sync for WsEvent
impl Unpin for WsEvent
impl UnwindSafe for WsEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.