aboutsummaryrefslogtreecommitdiff
path: root/src/lightstreamer_client.rs
diff options
context:
space:
mode:
authorLibravatar Daniel López Azaña <daniloaz@gmail.com>2024-03-28 19:19:46 +0100
committerLibravatar Daniel López Azaña <daniloaz@gmail.com>2024-03-28 19:19:46 +0100
commite1c0e90581b7ce97f87ddf43267ceb32e28447e3 (patch)
treea347bfed5552256fcbe5d54798814a1a1d24cf0a /src/lightstreamer_client.rs
parentb4e12fd1165b5e3960a1294dadec45eb40893b37 (diff)
✨ (client_listener.rs): Implement Debug trait for ClientListener for better logging
♻️ (connection_details.rs): Refactor ConnectionDetails to use Option for optional fields ♻️ (connection_details.rs): Change new constructor to accept &str and convert to String ✨ (connection_details.rs): Implement Debug trait for ConnectionDetails ♻️ (connection_options.rs): Implement Debug trait for ConnectionOptions ♻️ (lightstreamer_client.rs): Refactor LightstreamerClient to use Option for server_address and adapter_set ✨ (lightstreamer_client.rs): Implement Debug trait for LightstreamerClient ♻️ (main.rs): Update subscribe_to_channel function to use new control.txt URL and parameters ♻️ (main.rs): Update main function to use Option<&str> when creating LightstreamerClient ✨ (proxy.rs): Add Proxy struct and ProxyType enum to handle proxy configurations
Diffstat (limited to 'src/lightstreamer_client.rs')
-rw-r--r--src/lightstreamer_client.rs66
1 files changed, 58 insertions, 8 deletions
diff --git a/src/lightstreamer_client.rs b/src/lightstreamer_client.rs
index f91e843..214a722 100644
--- a/src/lightstreamer_client.rs
+++ b/src/lightstreamer_client.rs
@@ -6,6 +6,7 @@ use crate::subscription::Subscription;
use crate::IllegalStateException;
use cookie::Cookie;
+use std::fmt::{self, Debug, Formatter};
/// Facade class for the management of the communication to Lightstreamer Server. Used to provide
/// configuration settings, event handlers, operations for the control of the connection lifecycle,
@@ -45,8 +46,8 @@ use cookie::Cookie;
/// * `IllegalArgumentException`: if a not valid address is passed. See `ConnectionDetails.setServerAddress()`
/// for details.
pub struct LightstreamerClient {
- server_address: String,
- adapter_set: String,
+ server_address: Option<String>,
+ adapter_set: Option<String>,
/// Data object that contains the details needed to open a connection to a Lightstreamer Server.
/// This instance is set up by the `LightstreamerClient` object at its own creation. Properties
/// of this object can be overwritten by values received from a Lightstreamer Server.
@@ -59,6 +60,19 @@ pub struct LightstreamerClient {
subscriptions: Vec<Subscription>,
}
+impl Debug for LightstreamerClient {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ f.debug_struct("LightstreamerClient")
+ .field("server_address", &self.server_address)
+ .field("adapter_set", &self.adapter_set)
+ .field("connection_details", &self.connection_details)
+ .field("connection_options", &self.connection_options)
+ .field("listeners", &self.listeners)
+ .field("subscriptions", &self.subscriptions)
+ .finish()
+ }
+}
+
impl LightstreamerClient {
/// A constant string representing the name of the library.
pub const LIB_NAME: &'static str = "rust_client";
@@ -232,13 +246,49 @@ impl LightstreamerClient {
&self.subscriptions
}
- pub fn new (server_address: &str, adapter_set: &str) -> Result<LightstreamerClient, IllegalStateException> {
- let connection_details = ConnectionDetails::new(
- server_address.to_string(),
- adapter_set.to_string(),
- );
+ /// Creates a new instance of `LightstreamerClient`.
+ ///
+ /// The constructor initializes the client with the server address and adapter set, if provided.
+ /// It sets up the connection details and options for the client. If no server address or
+ /// adapter set is specified, those properties on the client will be `None`. This allows
+ /// for late configuration of these details before connecting to the Lightstreamer server.
+ ///
+ /// # Arguments
+ /// * `server_address` - An optional reference to a string slice that represents the server
+ /// address to connect to. If `None`, the server address must be set later.
+ /// * `adapter_set` - An optional reference to a string slice that specifies the adapter set name.
+ /// If `None`, the adapter set must be set later.
+ ///
+ /// # Returns
+ /// A result containing the new `LightstreamerClient` instance if successful, or an
+ /// `IllegalStateException` if the initialization fails due to invalid state conditions.
+ ///
+ /// # Panics
+ /// Does not panic under normal circumstances. However, unexpected internal errors during
+ /// the creation of internal components could cause panics, which should be considered when
+ /// using this function in production code.
+ ///
+ /// # Example
+ /// ```
+ /// // Example usage of `new` to create a LightstreamerClient with specified server address and
+ /// // adapter set.
+ /// let server_address = Some("http://myserver.com");
+ /// let adapter_set = Some("MY_ADAPTER_SET");
+ /// let ls_client = LightstreamerClient::new(server_address, adapter_set);
+ ///
+ /// assert!(ls_client.is_ok());
+ /// if let Ok(client) = ls_client {
+ /// assert_eq!(client.server_address.unwrap(), "http://myserver.com".to_string());
+ /// assert_eq!(client.adapter_set.unwrap(), "MY_ADAPTER_SET".to_string());
+ /// }
+ /// ```
+ pub fn new(
+ server_address: Option<&str>,
+ adapter_set: Option<&str>,
+ ) -> Result<LightstreamerClient, IllegalStateException> {
+ let connection_details = ConnectionDetails::new(server_address, adapter_set);
let connection_options = ConnectionOptions::new();
-
+
Ok(LightstreamerClient {
server_address: server_address.map(|s| s.to_string()),
adapter_set: adapter_set.map(|s| s.to_string()),