diff options
author | 2024-04-13 21:24:12 +0200 | |
---|---|---|
committer | 2024-04-13 21:24:12 +0200 | |
commit | 65282048aefecda06f937ed670755b64b19ce9b1 (patch) | |
tree | 1a026ad96955820ab72b02dba79c3c3b8662cacd /src/subscription.rs | |
parent | 5af8a69942aeed85b5cd2bd84cb5f33169834690 (diff) |
⬆️ (Cargo.toml): Bump lightstreamer-client version from 0.1.8 to 0.1.9
✨ (Cargo.toml): Add colored dependency to enhance console output
📝 (README.md): Overhaul documentation to provide comprehensive details about the project, its features, usage, and contribution guidelines
💡 (client_listener.rs, client_message_listener.rs): Add newline at end of file to adhere to POSIX standards
♻️ (connection_options.rs): Refactor code to improve readability and maintainability
🐛 (connection_options.rs): Rename 'reduce_head' to '_reduce_head' to indicate unused variable
♻️ (error.rs): Reorder imports and adjust formatting for consistency
♻️ (item_update.rs): Refactor code to improve readability and maintainability
♻️ (lib.rs): Reorder module imports for better organization
♻️ (ls_client.rs): Refactor code to improve readability and maintainability
💡 (main.rs): Update print statements to use colored output for changed fields
🐛 (main.rs): Fix import order to follow Rust's idiomatic style
🐛 (proxy.rs, subscription.rs, subscription_listener.rs): Add newline at end of file to follow POSIX standard
♻️ (subscription.rs, subscription_listener.rs): Refactor code to improve readability and maintainability
📝 (util.rs): Add newline at end of file to adhere to POSIX standards
Diffstat (limited to 'src/subscription.rs')
-rw-r--r-- | src/subscription.rs | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/src/subscription.rs b/src/subscription.rs index 9252ee6..135996b 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -39,18 +39,6 @@ pub enum SubscriptionMode { Command, } -impl SubscriptionMode { - fn from_str(s: &str) -> Result<SubscriptionMode, String> { - match s.to_lowercase().as_str() { - "merge" => Ok(SubscriptionMode::Merge), - "distinct" => Ok(SubscriptionMode::Distinct), - "raw" => Ok(SubscriptionMode::Raw), - "command" => Ok(SubscriptionMode::Command), - _ => Err(format!("Invalid subscription mode: {}", s)), - } - } -} - impl ToString for SubscriptionMode { fn to_string(&self) -> String { match self { @@ -171,15 +159,15 @@ impl Subscription { /// # See also /// `addListener()` pub fn remove_listener<T>(&mut self, listener: &T) - where - T: SubscriptionListener, - { - self.listeners.retain(|l| { - let l_ref = l.as_ref() as &dyn SubscriptionListener; - let listener_ref = listener as &dyn SubscriptionListener; - !(std::ptr::addr_of!(*l_ref) == std::ptr::addr_of!(*listener_ref)) - }); - } + where + T: SubscriptionListener, + { + self.listeners.retain(|l| { + let l_ref = l.as_ref() as &dyn SubscriptionListener; + let listener_ref = listener as &dyn SubscriptionListener; + !(std::ptr::addr_of!(*l_ref) == std::ptr::addr_of!(*listener_ref)) + }); + } /// Returns a list containing the SubscriptionListener instances that were added to this client. /// @@ -404,7 +392,10 @@ impl Subscription { /// /// # See also /// `Subscription.setCommandSecondLevelFieldSchema()` - pub fn set_command_second_level_data_adapter(&mut self, adapter: Option<String>) -> Result<(), String> { + pub fn set_command_second_level_data_adapter( + &mut self, + adapter: Option<String>, + ) -> Result<(), String> { if self.is_active { return Err("Subscription is active".to_string()); } @@ -457,7 +448,10 @@ impl Subscription { /// /// # See also /// `Subscription.setCommandSecondLevelFields()` - pub fn set_command_second_level_field_schema(&mut self, schema: Option<String>) -> Result<(), String> { + pub fn set_command_second_level_field_schema( + &mut self, + schema: Option<String>, + ) -> Result<(), String> { if self.is_active { return Err("Subscription is active".to_string()); } @@ -511,7 +505,10 @@ impl Subscription { /// /// # See also /// `Subscription.setCommandSecondLevelFieldSchema()` - pub fn set_command_second_level_fields(&mut self, fields: Option<Vec<String>>) -> Result<(), String> { + pub fn set_command_second_level_fields( + &mut self, + fields: Option<Vec<String>>, + ) -> Result<(), String> { if self.is_active { return Err("Subscription is active".to_string()); } @@ -763,7 +760,12 @@ impl Subscription { /// /// # Returns /// The current value for the specified field of the specified key within the specified item (possibly `None`), or `None` if the specified key has not been added yet (note that it might have been added and eventually deleted). - pub fn get_command_value(&self, item_pos: usize, key: &str, field_pos: usize) -> Option<&String> { + pub fn get_command_value( + &self, + item_pos: usize, + key: &str, + field_pos: usize, + ) -> Option<&String> { let key = format!("{}_{}", item_pos, key); self.command_values .get(&key) @@ -842,7 +844,9 @@ impl Subscription { return None; } if let Some(ref schema) = self.field_schema { - return schema.split(',').position(|field| field.trim() == "command"); + return schema + .split(',') + .position(|field| field.trim() == "command"); } None } @@ -896,9 +900,18 @@ impl Debug for Subscription { .field("field_schema", &self.field_schema) .field("fields", &self.fields) .field("data_adapter", &self.data_adapter) - .field("command_second_level_data_adapter", &self.command_second_level_data_adapter) - .field("command_second_level_field_schema", &self.command_second_level_field_schema) - .field("command_second_level_fields", &self.command_second_level_fields) + .field( + "command_second_level_data_adapter", + &self.command_second_level_data_adapter, + ) + .field( + "command_second_level_field_schema", + &self.command_second_level_field_schema, + ) + .field( + "command_second_level_fields", + &self.command_second_level_fields, + ) .field("requested_buffer_size", &self.requested_buffer_size) .field("requested_max_frequency", &self.requested_max_frequency) .field("requested_snapshot", &self.requested_snapshot) @@ -907,4 +920,4 @@ impl Debug for Subscription { .field("is_subscribed", &self.is_subscribed) .finish() } -}
\ No newline at end of file +} |