From 5af8a69942aeed85b5cd2bd84cb5f33169834690 Mon Sep 17 00:00:00 2001 From: daniloaz Date: Sat, 13 Apr 2024 12:21:12 +0200 Subject: ✨ (Cargo.toml): Bump package version to 0.1.8 for new changes ♻️ (item_update.rs): Refactor ItemUpdate struct and related methods to store only non-null changed fields ♻️ (ls_client.rs): Refactor data update handling to store updates in a HashMap and call on_item_update for each listener 🐛 (ls_client.rs): Fix item index off-by-one error in data update handling 🐛 (main.rs): Update on_item_update implementation to handle new ItemUpdate structure ♻️ (subscription_listener.rs): Refactor on_item_update method to take a reference to ItemUpdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 4959652..c284605 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,11 +43,34 @@ async fn setup_signal_hook(shutdown_signal: Arc) { pub struct MySubscriptionListener {} impl SubscriptionListener for MySubscriptionListener { - fn on_item_update(&mut self, update: ItemUpdate) { + fn on_item_update(&self, update: &ItemUpdate) { println!( - "UPDATE {} {}", - update.get_value("stock_name").unwrap(), - update.get_value("last_price").unwrap() + "UPDATE for item '{}' => '{}': {}, '{}': {}, '{}': {}, '{}': {}, '{}': {}, '{}': {}, '{}': {}, '{}': {}, '{}': {}, '{}': {}, '{}': {}, '{}': {}", + update.item_name.as_ref().unwrap_or(&"N/A".to_string()), + "stock_name", + update.get_value("stock_name").unwrap_or(&"N/A".to_string()), + "last_price", + update.get_value("last_price").unwrap_or(&"N/A".to_string()), + "time", + update.get_value("time").unwrap_or(&"N/A".to_string()), + "pct_change", + update.get_value("pct_change").unwrap_or(&"N/A".to_string()), + "bid_quantity", + update.get_value("bid_quantity").unwrap_or(&"N/A".to_string()), + "bid", + update.get_value("bid").unwrap_or(&"N/A".to_string()), + "ask", + update.get_value("ask").unwrap_or(&"N/A".to_string()), + "ask_quantity", + update.get_value("ask_quantity").unwrap_or(&"N/A".to_string()), + "min", + update.get_value("min").unwrap_or(&"N/A".to_string()), + "max", + update.get_value("max").unwrap_or(&"N/A".to_string()), + "ref_price", + update.get_value("ref_price").unwrap_or(&"N/A".to_string()), + "open_price", + update.get_value("open_price").unwrap_or(&"N/A".to_string()), ); } } -- cgit v1.2.3