pub struct WebSocketConfig {
pub url: String,
pub headers: Vec<(String, String)>,
pub message_handler: Option<MessageHandler>,
pub heartbeat: Option<u64>,
pub heartbeat_msg: Option<String>,
pub ping_handler: Option<PingHandler>,
pub reconnect_timeout_ms: Option<u64>,
pub reconnect_delay_initial_ms: Option<u64>,
pub reconnect_delay_max_ms: Option<u64>,
pub reconnect_backoff_factor: Option<f64>,
pub reconnect_jitter_ms: Option<u64>,
}
Expand description
Configuration for WebSocket client connections.
§Connection Modes
The message_handler
field determines the connection mode:
§Handler Mode (message_handler: Some(...)
)
- Use with
WebSocketClient::connect
. - Client spawns internal task to read messages and call handler.
- Supports automatic reconnection with exponential backoff.
- Reconnection config fields (
reconnect_*
) are active. - Best for long-lived connections, Python bindings, callback-based APIs.
§Stream Mode (message_handler: None
)
- Use with
WebSocketClient::connect_stream
. - Returns a
MessageReader
stream for the caller to read from. - Does NOT support automatic reconnection (reader owned by caller).
- Reconnection config fields are ignored.
- On disconnect, client transitions to CLOSED state and caller must manually reconnect.
Fields§
§url: String
The URL to connect to.
headers: Vec<(String, String)>
The default headers.
message_handler: Option<MessageHandler>
The function to handle incoming messages.
Some(handler)
: Handler mode with automatic reconnection (use withconnect
).None
: Stream mode without automatic reconnection (use withconnect_stream
).
See WebSocketConfig
docs for detailed explanation of modes.
heartbeat: Option<u64>
The optional heartbeat interval (seconds).
heartbeat_msg: Option<String>
The optional heartbeat message.
ping_handler: Option<PingHandler>
The handler for incoming pings.
reconnect_timeout_ms: Option<u64>
The timeout (milliseconds) for reconnection attempts.
Note: Only applies to handler mode. Ignored in stream mode.
reconnect_delay_initial_ms: Option<u64>
The initial reconnection delay (milliseconds) for reconnects.
Note: Only applies to handler mode. Ignored in stream mode.
reconnect_delay_max_ms: Option<u64>
The maximum reconnect delay (milliseconds) for exponential backoff.
Note: Only applies to handler mode. Ignored in stream mode.
reconnect_backoff_factor: Option<f64>
The exponential backoff factor for reconnection delays.
Note: Only applies to handler mode. Ignored in stream mode.
reconnect_jitter_ms: Option<u64>
The maximum jitter (milliseconds) added to reconnection delays.
Note: Only applies to handler mode. Ignored in stream mode.
Trait Implementations§
Source§impl Clone for WebSocketConfig
impl Clone for WebSocketConfig
Source§impl Debug for WebSocketConfig
impl Debug for WebSocketConfig
Source§impl<'py> IntoPyObject<'py> for WebSocketConfig
impl<'py> IntoPyObject<'py> for WebSocketConfig
Source§type Target = WebSocketConfig
type Target = WebSocketConfig
Source§type Output = Bound<'py, <WebSocketConfig as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <WebSocketConfig as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for WebSocketConfig
impl PyClass for WebSocketConfig
Source§impl PyClassImpl for WebSocketConfig
impl PyClassImpl for WebSocketConfig
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// Configuration for WebSocket client connections.
///
/// # Connection Modes
///
/// The `message_handler` field determines the connection mode:
///
/// ## Handler Mode (`message_handler: Some(...)`)
/// - Use with [`WebSocketClient::connect`].
/// - Client spawns internal task to read messages and call handler.
/// - **Supports automatic reconnection** with exponential backoff.
/// - Reconnection config fields (`reconnect_*`) are active.
/// - Best for long-lived connections, Python bindings, callback-based APIs.
///
/// ## Stream Mode (`message_handler: None`)
/// - Use with [`WebSocketClient::connect_stream`].
/// - Returns a [`MessageReader`] stream for the caller to read from.
/// - **Does NOT support automatic reconnection** (reader owned by caller).
/// - Reconnection config fields are ignored.
/// - On disconnect, client transitions to CLOSED state and caller must manually reconnect.
const RAW_DOC: &'static CStr = /// Configuration for WebSocket client connections. /// /// # Connection Modes /// /// The `message_handler` field determines the connection mode: /// /// ## Handler Mode (`message_handler: Some(...)`) /// - Use with [`WebSocketClient::connect`]. /// - Client spawns internal task to read messages and call handler. /// - **Supports automatic reconnection** with exponential backoff. /// - Reconnection config fields (`reconnect_*`) are active. /// - Best for long-lived connections, Python bindings, callback-based APIs. /// /// ## Stream Mode (`message_handler: None`) /// - Use with [`WebSocketClient::connect_stream`]. /// - Returns a [`MessageReader`] stream for the caller to read from. /// - **Does NOT support automatic reconnection** (reader owned by caller). /// - Reconnection config fields are ignored. /// - On disconnect, client transitions to CLOSED state and caller must manually reconnect.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature
if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<WebSocketConfig>
type ThreadChecker = SendablePyClass<WebSocketConfig>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for WebSocketConfig
impl PyClassNewTextSignature for WebSocketConfig
const TEXT_SIGNATURE: &'static str = "(url, handler, headers, heartbeat=None, heartbeat_msg=None, ping_handler=None, reconnect_timeout_ms=10000, reconnect_delay_initial_ms=2000, reconnect_delay_max_ms=30000, reconnect_backoff_factor=1.5, reconnect_jitter_ms=100)"
Source§impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder WebSocketConfig
impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder WebSocketConfig
Source§impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder mut WebSocketConfig
impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder mut WebSocketConfig
Source§impl PyMethods<WebSocketConfig> for PyClassImplCollector<WebSocketConfig>
impl PyMethods<WebSocketConfig> for PyClassImplCollector<WebSocketConfig>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for WebSocketConfig
impl PyTypeInfo for WebSocketConfig
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object
is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object
is an instance of this type.impl DerefToPyAny for WebSocketConfig
Auto Trait Implementations§
impl Freeze for WebSocketConfig
impl !RefUnwindSafe for WebSocketConfig
impl Send for WebSocketConfig
impl Sync for WebSocketConfig
impl Unpin for WebSocketConfig
impl !UnwindSafe for WebSocketConfig
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,
§impl<T> FromPyObject<'_> for Twhere
T: PyClass + Clone,
impl<T> FromPyObject<'_> for Twhere
T: PyClass + Clone,
§fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>
fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>
§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
§fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self
into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self
into an owned Python object, dropping type information and unbinding it
from the 'py
lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self
into a Python object. Read more