From 15ba8a15ab5bd10cf2b7868bccb292ac0f7dcc4b Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 23 Apr 2024 09:51:23 +0200 Subject: [PATCH] simplify some code Signed-off-by: Wolfgang Bumiller --- proxmox-auto-installer/src/sysinfo.rs | 15 ++++++++------- proxmox-auto-installer/src/utils.rs | 3 +-- proxmox-fetch-answer/src/fetch_plugins/http.rs | 5 ++--- proxmox-installer-common/src/disk_checks.rs | 4 +--- proxmox-installer-common/src/setup.rs | 10 +++++----- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/proxmox-auto-installer/src/sysinfo.rs b/proxmox-auto-installer/src/sysinfo.rs index a9b9ffd..05f7f50 100644 --- a/proxmox-auto-installer/src/sysinfo.rs +++ b/proxmox-auto-installer/src/sysinfo.rs @@ -76,22 +76,23 @@ struct SystemDMI { impl SystemDMI { pub(crate) fn get() -> Result { - let system_files = vec![ + let system_files = [ "product_serial", "product_sku", "product_uuid", "product_name", ]; - let baseboard_files = vec!["board_asset_tag", "board_serial", "board_name"]; - let chassis_files = vec!["chassis_serial", "chassis_sku", "chassis_asset_tag"]; + let baseboard_files = ["board_asset_tag", "board_serial", "board_name"]; + let chassis_files = ["chassis_serial", "chassis_sku", "chassis_asset_tag"]; Ok(Self { - system: Self::get_dmi_infos(system_files)?, - baseboard: Self::get_dmi_infos(baseboard_files)?, - chassis: Self::get_dmi_infos(chassis_files)?, + system: Self::get_dmi_infos(&system_files)?, + baseboard: Self::get_dmi_infos(&baseboard_files)?, + chassis: Self::get_dmi_infos(&chassis_files)?, }) } - fn get_dmi_infos(files: Vec<&str>) -> Result> { + + fn get_dmi_infos(files: &[&str]) -> Result> { let mut res: HashMap = HashMap::new(); for file in files { diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index f393590..5588788 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -101,8 +101,7 @@ pub fn get_nic_list() -> Result> { .arg("-j") .arg("link") .output()?; - let parsed_links: Vec = - serde_json::from_str(String::from_utf8(ip_output.stdout)?.as_str())?; + let parsed_links: Vec = serde_json::from_slice(&ip_output.stdout)?; let mut links: Vec = Vec::new(); for link in parsed_links { diff --git a/proxmox-fetch-answer/src/fetch_plugins/http.rs b/proxmox-fetch-answer/src/fetch_plugins/http.rs index ae29196..11641e8 100644 --- a/proxmox-fetch-answer/src/fetch_plugins/http.rs +++ b/proxmox-fetch-answer/src/fetch_plugins/http.rs @@ -60,9 +60,8 @@ impl FetchFromHTTP { }; } - if fingerprint.is_some() { - let fp = fingerprint.clone(); - fs::write("/tmp/cert_fingerprint", fp.unwrap()).ok(); + if let Some(fingerprint) = &fingerprint { + let _ = fs::write("/tmp/cert_fingerprint", fingerprint); } info!("Gathering system information."); diff --git a/proxmox-installer-common/src/disk_checks.rs b/proxmox-installer-common/src/disk_checks.rs index 7cbdf19..89b300c 100644 --- a/proxmox-installer-common/src/disk_checks.rs +++ b/proxmox-installer-common/src/disk_checks.rs @@ -42,9 +42,7 @@ pub fn check_raid_min_disks(disks: &[Disk], min: usize) -> Result<(), String> { /// * `runinfo` - `RuntimeInfo` instance of currently running system /// * `disks` - List of disks designated as bootdisk targets. pub fn check_disks_4kn_legacy_boot(boot_type: BootType, disks: &[Disk]) -> Result<(), &str> { - let is_blocksize_4096 = |disk: &Disk| disk.block_size.map(|s| s == 4096).unwrap_or(false); - - if boot_type == BootType::Bios && disks.iter().any(is_blocksize_4096) { + if boot_type == BootType::Bios && disks.iter().any(|disk| disk.block_size == Some(4096)) { return Err("Booting from 4Kn drive in legacy BIOS mode is not supported."); } diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs index c4a92f9..8a7bdee 100644 --- a/proxmox-installer-common/src/setup.rs +++ b/proxmox-installer-common/src/setup.rs @@ -40,11 +40,11 @@ impl ProxmoxProduct { impl fmt::Display for ProxmoxProduct { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::PVE => write!(f, "pve"), - Self::PMG => write!(f, "pmg"), - Self::PBS => write!(f, "pbs"), - } + f.write_str(match self { + Self::PVE => "pve", + Self::PMG => "pmg", + Self::PBS => "pbs", + }) } } -- 2.39.5