pub struct ConnectOptions<'a> {
pub username: Option<&'a str>,
pub password: Option<&'a str>,
pub timeout: Option<Duration>,
pub reconnect: ReconnectBehavior,
pub tls_config: Option<Arc<ClientConfig>>,
pub reconnector: Option<Arc<dyn Reconnector>>,
}Fields§
§username: Option<&'a str>§password: Option<&'a str>§timeout: Option<Duration>§reconnect: ReconnectBehaviorWhether the returned client should reconnect automatically when the WebSocket
connection drops. Defaults to ReconnectBehavior::Enabled(ReconnectPolicy::default()) -
set this to ReconnectBehavior::Disabled to get the old one-shot-connection behavior.
tls_config: Option<Arc<ClientConfig>>Custom TLS trust config for wss:// addresses. None (the default) uses
tokio-tungstenite’s built-in rustls-tls-webpki-roots default, which only trusts
public CAs - it cannot validate a CSMS certificate issued by a private/internal CA.
Build a rustls::ClientConfig with a RootCertStore containing that CA’s certificate
(and optionally client-cert auth for mTLS) and set it here to connect to such a CSMS.
ocpp_client::rustls re-exports the exact rustls version this crate was built
against, so the ClientConfig you build is guaranteed compatible. Reconnect attempts
(see reconnect above) reuse the same config.
reconnector: Option<Arc<dyn Reconnector>>Decides where a dropped connection is redialled. None (the default) redials the same
address, protocol, credentials and TLS config the connection started with, which is what
almost every caller wants.
Supply one to make the redial target something other than a constant - the case this
exists for is a charge point that must move to a different CSMS address (an OCPP 2.x
network connection profile, a failover endpoint) without tearing down its Client.
Reconnecting through the same Client keeps its identity, so every registered handler,
every in-flight request and every queued message survives the move; dropping the client
and calling connect_* again does not.
Implementations usually delegate to websocket_transport rather than building a
transport by hand - see its docs for a worked reconnector. A custom reconnector is fully
responsible for the redial: address and the credential/TLS fields above apply to the
initial connection only and are not consulted when it runs.
ReconnectBehavior::Disabled still wins - it is an explicit “do not redial”, and
supplying a reconnector does not quietly turn reconnect back on.
Trait Implementations§
Source§impl<'a> Clone for ConnectOptions<'a>
impl<'a> Clone for ConnectOptions<'a>
Source§fn clone(&self) -> ConnectOptions<'a>
fn clone(&self) -> ConnectOptions<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more