From be4b3fb75c7c2df48bbb97f66d86048a8f9e62f6 Mon Sep 17 00:00:00 2001 From: Vignesh Rao Date: Wed, 25 Sep 2024 22:33:51 -0500 Subject: [PATCH] Reformat and restructure code --- src/legacy/disks.rs | 14 +++++++------- src/resources/info.rs | 12 ++++++------ src/resources/stream.rs | 2 +- src/routes/auth.rs | 4 ++-- src/squire/util.rs | 6 +++--- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/legacy/disks.rs b/src/legacy/disks.rs index 5a00223..5a07b8b 100644 --- a/src/legacy/disks.rs +++ b/src/legacy/disks.rs @@ -1,7 +1,7 @@ -use std::collections::HashMap; -use std::str; use regex::Regex; use serde_json::Value; +use std::collections::HashMap; +use std::str; use crate::legacy::helper::{run_command, size_converter}; @@ -53,7 +53,7 @@ fn is_physical_disk(lib_path: &str, device_id: &str) -> bool { Err(_) => { log::error!("Failed to get disk info"); return false; - }, + } }; for line in output.split("\n") { if line.contains("Virtual:") && line.contains("Yes") { @@ -79,7 +79,7 @@ fn linux_disks(lib_path: &str) -> Vec> { Err(_) => { log::error!("Failed to get disk info"); return Vec::new(); - }, + } }; let disks: Vec<&str> = output.lines().collect(); let filtered_disks: Vec<&str> = disks.into_iter().filter(|&disk| !disk.contains("loop")).collect(); @@ -118,7 +118,7 @@ fn darwin_disks(lib_path: &str) -> Vec> { Err(_) => { log::error!("Failed to get disk info"); return Vec::new(); - }, + } }; let disks: Vec<&str> = output.lines().collect(); let disk_lines: Vec<&str> = disks.into_iter().filter(|&line| line.starts_with("/dev/disk")).collect(); @@ -134,7 +134,7 @@ fn darwin_disks(lib_path: &str) -> Vec> { Err(_) => { log::error!("Failed to get disk info"); return Vec::new(); - }, + } }; let info_lines: Vec<&str> = disk_info_output.lines().collect(); let mut disk_data = HashMap::new(); @@ -189,7 +189,7 @@ fn windows_disks(lib_path: &str) -> Vec> { Err(_) => { log::error!("Failed to get disk info"); return Vec::new(); - }, + } }; let disks_info: Value = serde_json::from_str(&output).unwrap(); let mut disk_info = Vec::new(); diff --git a/src/resources/info.rs b/src/resources/info.rs index 18b5a7b..db9c484 100644 --- a/src/resources/info.rs +++ b/src/resources/info.rs @@ -1,9 +1,9 @@ -use crate::{resources, squire, legacy}; +use crate::{legacy, resources, squire}; use chrono::Utc; use std::collections::HashMap; use std::collections::HashSet; -use sysinfo::System; use sysinfo::Disks; +use sysinfo::System; /// Function to get total disk usage. /// @@ -58,11 +58,11 @@ fn get_cpu_brand(sys: &System) -> String { if cpu_brands.is_empty() { log::warn!("Unable to get brand information for all {} CPUs", cpus.len()); let legacy_cpu_brand_name = legacy::cpu_brand::get_name(); - return if legacy_cpu_brand_name.is_some() { - legacy_cpu_brand_name.unwrap() + return if let Some(cpu_brand) = legacy_cpu_brand_name { + cpu_brand } else { "Unknown".to_string() - } + }; } let mut cpu_brand_list: Vec = cpu_brands.into_iter().collect(); cpu_brand_list.sort_by_key(|brand| brand.len()); @@ -105,7 +105,7 @@ pub fn get_sys_info(disks: &Disks) -> HashMap<&'static str, HashMap<&'static str ("Uptime", uptime), ("CPU cores", sys.cpus().len().to_string()), ("CPU brand", get_cpu_brand(&sys)) - ]); + ]); let mut hash_vec = vec![ ("Memory", total_memory), ("Storage", total_storage) diff --git a/src/resources/stream.rs b/src/resources/stream.rs index 9bd7f48..61dd26f 100644 --- a/src/resources/stream.rs +++ b/src/resources/stream.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use sysinfo::{CpuRefreshKind, Disks, RefreshKind, System}; -use crate::{squire, resources}; +use crate::{resources, squire}; use serde_json::{self, Value}; /// Function to get disk statistics. diff --git a/src/routes/auth.rs b/src/routes/auth.rs index 52ec256..e2e6d6b 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -1,9 +1,9 @@ use std::sync::Arc; -use actix_web::{HttpRequest, HttpResponse, web}; -use actix_web::cookie::{Cookie, SameSite}; use actix_web::cookie::time::{Duration, OffsetDateTime}; +use actix_web::cookie::{Cookie, SameSite}; use actix_web::http::StatusCode; +use actix_web::{web, HttpRequest, HttpResponse}; use fernet::Fernet; use minijinja; use serde::Serialize; diff --git a/src/squire/util.rs b/src/squire/util.rs index d335f24..e6b0eea 100644 --- a/src/squire/util.rs +++ b/src/squire/util.rs @@ -1,6 +1,6 @@ use regex::Regex; -use std::process::Command; use std::collections::HashMap; +use std::process::Command; /// Function to retrieve the REGEX object for an IPv4 address format /// @@ -27,8 +27,8 @@ pub fn public_ip_mapping() -> HashMap { ("https://httpbin.org/ip".to_string(), false), // expects JSON ("https://myip.dnsomatic.com/".to_string(), true), // expects text ] - .into_iter() - .collect(); + .into_iter() + .collect(); mapping }