diff options
author | 2024-04-05 16:29:01 +0200 | |
---|---|---|
committer | 2024-04-05 16:29:01 +0200 | |
commit | 1d74478512faafdb2263b0d11773190c9efe3190 (patch) | |
tree | 88e1716350a01d1cad03637828e82bc23fe829be /src/connection_details.rs | |
parent | 0a1fa8873aa430f13735772cd0e8bff7c7ffc16c (diff) |
⬆️ (Cargo.toml): bump version to 0.1.2 for new release
♻️ (connection_details.rs): refactor `new` method to return Result for better error handling
✨ (connection_details.rs): set default adapter set to "DEFAULT" if none provided
✨ (ls_client.rs): update `new` method to handle Result from ConnectionDetails::new
🐛 (main.rs): fix subscription item list to include correct items
♻️ (main.rs): replace magic number with constant for max connection attempts
Diffstat (limited to 'src/connection_details.rs')
-rw-r--r-- | src/connection_details.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/connection_details.rs b/src/connection_details.rs index 228a597..916c396 100644 --- a/src/connection_details.rs +++ b/src/connection_details.rs @@ -1,6 +1,7 @@ use crate::client_listener::ClientListener; use crate::error::IllegalArgumentException; +use std::error::Error; use std::fmt::{self, Debug, Formatter}; /// Used by `LightstreamerClient` to provide a basic connection properties data object. @@ -170,12 +171,12 @@ impl ConnectionDetails { } /// Creates a new ConnectionDetails object with default values. - pub fn new(server_address: Option<&str>, adapter_set: Option<&str>) -> ConnectionDetails { - ConnectionDetails { - server_address: server_address.map(|s| s.to_string()), // convert &str to String - adapter_set: adapter_set.map(|s| s.to_string()), // convert &str to String - ..Default::default() - } + pub fn new(server_address: Option<&str>, adapter_set: Option<&str>) -> Result<ConnectionDetails, Box<dyn Error>> { + let mut connection_details = ConnectionDetails::default(); + connection_details.set_server_address(server_address.map(|s| s.to_string()))?; + connection_details.set_adapter_set(adapter_set.map(|s| s.to_string())); + + Ok(connection_details) } /// Setter method that sets the name of the Adapter Set mounted on Lightstreamer Server to @@ -202,7 +203,7 @@ impl ConnectionDetails { /// * `adapter_set`: The name of the Adapter Set to be used. A `None` value is equivalent to /// the "DEFAULT" name. pub fn set_adapter_set(&mut self, adapter_set: Option<String>) { - self.adapter_set = adapter_set; + self.adapter_set = Some(adapter_set.unwrap_or("DEFAULT".to_string())); // Notify listeners about the property change for listener in &self.listeners { |