aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Daniel López Azaña <daniloaz@gmail.com>2024-03-28 20:55:23 +0100
committerLibravatar Daniel López Azaña <daniloaz@gmail.com>2024-03-28 20:55:23 +0100
commit68f73131aa0f993bfc1bfa622be63f8862661c16 (patch)
tree98a4d874f95111e7309a9b19d044ae024af74cd7
parent5c80b291fc776a7114572cebff898a7b3bf0671b (diff)
♻️ (ls_client.rs): refactor connect method to check server_address before connecting
✨ (main.rs): rename subscription to my_subscription for clarity ✨ (main.rs): move subscription setup before client creation ✨ (main.rs): add client.subscribe and client.connect calls to main function
-rw-r--r--src/ls_client.rs5
-rw-r--r--src/main.rs14
2 files changed, 12 insertions, 7 deletions
diff --git a/src/ls_client.rs b/src/ls_client.rs
index 214a722..59dd247 100644
--- a/src/ls_client.rs
+++ b/src/ls_client.rs
@@ -148,7 +148,10 @@ impl LightstreamerClient {
///
/// See also `ConnectionDetails.setServerAddress()`
pub fn connect(&mut self) -> Result<(), IllegalStateException> {
- // Implementation for connect
+ if self.server_address.is_none() {
+ return Err(IllegalStateException::new("No server address was configured."));
+ }
+
Ok(())
}
diff --git a/src/main.rs b/src/main.rs
index 5c2acc5..c120c1f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -210,7 +210,7 @@ impl SubscriptionListener for MySubscriptionListener {
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
- let mut subscription = Subscription::new(
+ let mut my_subscription = Subscription::new(
SubscriptionMode::Merge,
Some(vec![
"item1".to_string(),
@@ -220,17 +220,19 @@ async fn main() -> Result<(), Box<dyn Error>> {
Some(vec!["stock_name".to_string(), "last_price".to_string()]),
)?;
- subscription.add_listener(Box::new(MySubscriptionListener {}));
- subscription.set_data_adapter(Some(String::from("QUOTE_ADAPTER")))?;
- subscription.set_requested_snapshot(Some(Snapshot::Yes))?;
+ my_subscription.set_data_adapter(Some(String::from("QUOTE_ADAPTER")))?;
+ my_subscription.set_requested_snapshot(Some(Snapshot::Yes))?;
+ my_subscription.add_listener(Box::new(MySubscriptionListener {}));
- let client = LightstreamerClient::new(
+ let mut client = LightstreamerClient::new(
Some("http://push.lightstreamer.com/lightstreamer"),
Some("DEMO"),
)?;
- println!("Subscription: {:?}", subscription);
+ client.subscribe(my_subscription);
println!("Client: {:?}", client);
+ client.connect();
+
Ok(())
}