diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/core/c8y_smartrest/src/smartrest_deserializer.rs | 18 | ||||
-rw-r--r-- | crates/core/tedge_mapper/src/sm_c8y_mapper/mapper.rs | 2 |
2 files changed, 11 insertions, 9 deletions
diff --git a/crates/core/c8y_smartrest/src/smartrest_deserializer.rs b/crates/core/c8y_smartrest/src/smartrest_deserializer.rs index ceeba27c..52be56b9 100644 --- a/crates/core/c8y_smartrest/src/smartrest_deserializer.rs +++ b/crates/core/c8y_smartrest/src/smartrest_deserializer.rs @@ -44,15 +44,17 @@ pub struct SmartRestUpdateSoftwareModule { pub action: String, } -impl SmartRestUpdateSoftware { - pub fn new() -> Self { +impl Default for SmartRestUpdateSoftware { + fn default() -> Self { Self { message_id: "528".into(), external_id: "".into(), update_list: vec![], } } +} +impl SmartRestUpdateSoftware { pub fn from_smartrest(&self, smartrest: &str) -> Result<Self, SmartRestDeserializerError> { let mut message_id = smartrest.to_string(); let () = message_id.truncate(3); @@ -61,7 +63,7 @@ impl SmartRestUpdateSoftware { .has_headers(false) .flexible(true) .from_reader(smartrest.as_bytes()); - let mut record: Self = Self::new(); + let mut record: Self = Self::default(); for result in rdr.deserialize() { record = result?; @@ -382,7 +384,7 @@ mod tests { fn deserialize_smartrest_update_software() { let smartrest = String::from("528,external_id,software1,version1,url1,install,software2,,,delete"); - let update_software = SmartRestUpdateSoftware::new() + let update_software = SmartRestUpdateSoftware::default() .from_smartrest(&smartrest) .unwrap(); @@ -411,7 +413,7 @@ mod tests { #[test] fn deserialize_incorrect_smartrest_message_id() { let smartrest = String::from("516,external_id"); - assert!(SmartRestUpdateSoftware::new() + assert!(SmartRestUpdateSoftware::default() .from_smartrest(&smartrest) .is_err()); } @@ -420,7 +422,7 @@ mod tests { fn deserialize_incorrect_smartrest_action() { let smartrest = String::from("528,external_id,software1,version1,url1,action,software2,,,remove"); - assert!(SmartRestUpdateSoftware::new() + assert!(SmartRestUpdateSoftware::default() .from_smartrest(&smartrest) .unwrap() .to_thin_edge_json() @@ -475,7 +477,7 @@ mod tests { String::from("528,external_id,nodered,1.0.0::debian,,install,\ collectd,5.7::debian,https://collectd.org/download/collectd-tarballs/collectd-5.12.0.tar.bz2,install,\ nginx,1.21.0::docker,,install,mongodb,4.4.6::docker,,delete"); - let update_software = SmartRestUpdateSoftware::new(); + let update_software = SmartRestUpdateSoftware::default(); let software_update_request = update_software .from_smartrest(&smartrest) .unwrap() @@ -528,7 +530,7 @@ mod tests { fn access_smartrest_update_modules() { let smartrest = String::from("528,external_id,software1,version1,url1,install,software2,,,delete"); - let update_software = SmartRestUpdateSoftware::new(); + let update_software = SmartRestUpdateSoftware::default(); let vec = update_software .from_smartrest(&smartrest) .unwrap() diff --git a/crates/core/tedge_mapper/src/sm_c8y_mapper/mapper.rs b/crates/core/tedge_mapper/src/sm_c8y_mapper/mapper.rs index 88077a09..6c0fcd35 100644 --- a/crates/core/tedge_mapper/src/sm_c8y_mapper/mapper.rs +++ b/crates/core/tedge_mapper/src/sm_c8y_mapper/mapper.rs @@ -400,7 +400,7 @@ where smartrest: &str, ) -> Result<(), SMCumulocityMapperError> { let topic = Topic::new(RequestTopic::SoftwareUpdateRequest.as_str())?; - let update_software = SmartRestUpdateSoftware::new(); + let update_software = SmartRestUpdateSoftware::default(); let mut software_update_request = update_software .from_smartrest(smartrest)? .to_thin_edge_json()?; |