From 261a29d3bf0a4105857bcbb03aa9674d2d85f9bd Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Sat, 24 Aug 2024 15:37:20 +0200 Subject: [PATCH] pass clippy --- src/device_var.rs | 8 +++----- src/mqtt_pub.rs | 2 +- src/system_values.rs | 10 ++++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/device_var.rs b/src/device_var.rs index f475cb1..1d7aa32 100644 --- a/src/device_var.rs +++ b/src/device_var.rs @@ -9,11 +9,9 @@ pub fn read_env_var() { fs::read_to_string(path).expect("Something went wrong reading the file : device.env"); if let Ok(lines) = read_lines(path) { - for line in lines { - if let Ok(var) = line { - let new_var: Vec<&str> = var.split('=').collect(); - env::set_var(new_var[0], new_var[1]); - } + for var in lines.map_while(Result::ok) { + let new_var: Vec<&str> = var.split('=').collect(); + env::set_var(new_var[0], new_var[1]); } } diff --git a/src/mqtt_pub.rs b/src/mqtt_pub.rs index 78517b2..ec82ca5 100644 --- a/src/mqtt_pub.rs +++ b/src/mqtt_pub.rs @@ -41,7 +41,7 @@ pub fn get_topic_name(types: &str) -> String { let capteur = env::var("CAPTEUR").unwrap().to_string(); topic.push_str(&capteur); topic.push('/'); - topic.push_str(&types); + topic.push_str(types); topic } diff --git a/src/system_values.rs b/src/system_values.rs index 7ae024b..899fc2d 100644 --- a/src/system_values.rs +++ b/src/system_values.rs @@ -12,7 +12,7 @@ pub fn get_temperature() -> f32 { let temperature_string = &String::from_utf8_lossy(&temperature_command.stdout)[..5]; temperature = temperature_string.parse::().unwrap(); - temperature = temperature / 1000.0; + temperature /= 1000.0; } else { let temperature_command = Command::new("sudo") .arg("/opt/vc/bin/vcgencmd") @@ -39,9 +39,8 @@ pub fn get_storage() -> i8 { let vec_storage: Vec<&str> = storage_string.split_whitespace().collect(); let mut value = vec_storage[vec_storage.len() - 2].to_string(); value.pop(); - let storage = value.parse::().unwrap(); - storage + value.parse::().unwrap() } pub fn get_mem() -> i8 { @@ -54,9 +53,8 @@ pub fn get_mem() -> i8 { let vec_mem: Vec<&str> = mem_string.split_whitespace().collect(); let total = vec_mem[7].parse::().unwrap(); let mem_use = vec_mem[8].parse::().unwrap(); - let result = (mem_use / total * 100.0) as i8; - result + (mem_use / total * 100.0) as i8 } pub fn get_battery() -> i8 { @@ -70,7 +68,7 @@ pub fn get_battery() -> i8 { .unwrap_or_else(|e| panic!("failed to execute process: {}", e)); let battery_string = &String::from_utf8_lossy(&battery_command.stdout); - battery = (&battery_string[..battery_string.len() - 1]) + battery = (battery_string[..battery_string.len() - 1]) .parse::() .unwrap(); }