From 8aafbf7c916116ae44604259b8ced2f929b91a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fern=C3=A1ndez?= Date: Fri, 12 Jul 2024 15:40:06 +0200 Subject: [PATCH] Solved clippy report, clone_from and unwrap_or_default --- src/appconfig.rs | 12 ++++-------- src/logreader.rs | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/appconfig.rs b/src/appconfig.rs index 170fca6..14ed66e 100644 --- a/src/appconfig.rs +++ b/src/appconfig.rs @@ -349,10 +349,8 @@ impl AppConfig { // ------------------------------------------------------------------------ pub fn get_labels(&self, index: usize, array: Array) -> Vec { - match array[index]["labels"].clone().into_vec() { - Some(labels) => labels, - None => Vec::new() - }.to_vec().iter().map(|element| String::from(element.as_str().unwrap()) ).collect() + array[index]["labels"].clone().into_vec().unwrap_or_default() + .to_vec().iter().map(|element| String::from(element.as_str().unwrap()) ).collect() } // ------------------------------------------------------------------------ @@ -399,10 +397,8 @@ impl AppConfig { // ------------------------------------------------------------------------ pub fn get_integrations(&self, index: usize, array: Array) -> Vec { - let data = match array[index]["integrations"].clone().into_vec() { - Some(integrations) => integrations, - None => Vec::new() - }; + let default = array[index]["integrations"].clone().into_vec(); + let data = default.unwrap_or_default(); let mut integrations: Vec = Vec::new(); data.iter().for_each(|info| integrations.push(Integration::new( diff --git a/src/logreader.rs b/src/logreader.rs index 060fad0..8eb82f0 100644 --- a/src/logreader.rs +++ b/src/logreader.rs @@ -110,10 +110,10 @@ pub fn extract_fields(data: Vec>) -> (SHashMap, data.iter().for_each(|v| { match v["type"].as_str() { - "SYSCALL" => syscall = v.clone(), + "SYSCALL" => syscall.clone_from(v), "PATH" => paths.push(v.clone()), - "CWD" => cwd = v.clone(), - "PROCTITLE" => proctitle = v.clone(), + "CWD" => cwd.clone_from(v), + "PROCTITLE" => proctitle.clone_from(v), _ => error!("Unidentified Audit field") } });