diff --git a/src/tools/kata-ctl/src/arch/x86_64/mod.rs b/src/tools/kata-ctl/src/arch/x86_64/mod.rs index 379f8b6e5..95817981e 100644 --- a/src/tools/kata-ctl/src/arch/x86_64/mod.rs +++ b/src/tools/kata-ctl/src/arch/x86_64/mod.rs @@ -13,8 +13,8 @@ mod arch_specific { const PROC_CPUINFO: &str = "/proc/cpuinfo"; const CPUINFO_DELIMITER: &str = "\nprocessor"; const CPUINFO_FLAGS_TAG: &str = "flags"; - const CPU_FLAGS_INTEL: &'static [&'static str] = &["lm", "sse4_1", "vmx"]; - const CPU_ATTRIBS_INTEL: &'static [&'static str] = &["GenuineIntel"]; + const CPU_FLAGS_INTEL: &[&str] = &["lm", "sse4_1", "vmx"]; + const CPU_ATTRIBS_INTEL: &[&str] = &["GenuineIntel"]; // check cpu fn check_cpu() -> Result<()> { @@ -29,14 +29,14 @@ mod arch_specific { // TODO: Perform checks based on hypervisor type // TODO: Add more information to output (see kata-check in go tool); adjust formatting let missing_cpu_attributes = check::check_cpu_attribs(&cpu_info, CPU_ATTRIBS_INTEL)?; - if missing_cpu_attributes.len() > 0 { + if !missing_cpu_attributes.is_empty() { eprintln!( "WARNING: Missing CPU attributes {:?}", missing_cpu_attributes ); } let missing_cpu_flags = check::check_cpu_flags(&cpu_flags, CPU_FLAGS_INTEL)?; - if missing_cpu_flags.len() > 0 { + if !missing_cpu_flags.is_empty() { eprintln!("WARNING: Missing CPU flags {:?}", missing_cpu_flags); } diff --git a/src/tools/kata-ctl/src/check.rs b/src/tools/kata-ctl/src/check.rs index 4e96eee5b..28febb307 100644 --- a/src/tools/kata-ctl/src/check.rs +++ b/src/tools/kata-ctl/src/check.rs @@ -45,10 +45,10 @@ pub fn get_cpu_flags(cpu_info: &str, cpu_flags_tag: &str) -> Result { return Err(anyhow!("cpu_info string is empty"))?; } - let subcontents: Vec<&str> = cpu_info.split("\n").collect(); + let subcontents: Vec<&str> = cpu_info.split('\n').collect(); for line in subcontents { if line.starts_with(cpu_flags_tag) { - let line_data: Vec<&str> = line.split(":").collect(); + let line_data: Vec<&str> = line.split(':').collect(); let flags = line_data .last() .ok_or("error splitting flags in cpuinfo") @@ -64,12 +64,10 @@ pub fn get_cpu_flags(cpu_info: &str, cpu_flags_tag: &str) -> Result { // get_missing_strings searches for required (strings) in data and returns // a vector containing the missing strings fn get_missing_strings(data: &str, required: &'static [&'static str]) -> Result> { - let data_vec: Vec<&str> = data.split_whitespace().collect(); - let mut missing: Vec = Vec::new(); for item in required { - if !data_vec.contains(&item) { + if !data.split_whitespace().any(|x| x == *item) { missing.push(item.to_string()); } } @@ -90,8 +88,8 @@ pub fn check_cpu_attribs( cpu_info: &str, required_attribs: &'static [&'static str], ) -> Result> { - let mut cpu_info_processed = cpu_info.replace("\t", ""); - cpu_info_processed = cpu_info_processed.replace("\n", " "); + let mut cpu_info_processed = cpu_info.replace('\t', ""); + cpu_info_processed = cpu_info_processed.replace('\n', " "); let missing_attribs = get_missing_strings(&cpu_info_processed, required_attribs)?; Ok(missing_attribs) @@ -134,7 +132,7 @@ fn handle_reqwest_error(e: reqwest::Error) -> anyhow::Error { } pub fn check_version() -> Result<()> { - let version = get_kata_version_by_url(KATA_GITHUB_URL).map_err(|e| handle_reqwest_error(e))?; + let version = get_kata_version_by_url(KATA_GITHUB_URL).map_err(handle_reqwest_error)?; println!("Version: {}", version); diff --git a/src/tools/kata-ctl/src/ops/version.rs.in b/src/tools/kata-ctl/src/ops/version.rs.in index c207b0ea3..052eccf16 100644 --- a/src/tools/kata-ctl/src/ops/version.rs.in +++ b/src/tools/kata-ctl/src/ops/version.rs.in @@ -13,27 +13,27 @@ const KATA_CTL_VERSION: &str = "@KATA_CTL_VERSION@"; pub fn get() -> Result { if KATA_CTL_VERSION.trim().is_empty() { - return Err("Unable to retrieve kata Version. Check that Kata is properly installed".to_string()); - } - else { - let version=format!("{}-{}", KATA_CTL_VERSION, crate_version!()); - return Ok(version); + Err("Unable to retrieve kata Version. Check that Kata is properly installed".to_string()) + } else { + let version = format!("{}-{}", KATA_CTL_VERSION, crate_version!()); + + Ok(version) } } #[cfg(test)] mod tests { use super::*; - use semver::{Version}; + use semver::Version; #[test] fn test_get() { let version = get().unwrap(); - let v = Version::parse(&version).unwrap(); + let v = Version::parse(&version).unwrap(); - assert!(!v.major.to_string().is_empty()); - assert!(!v.minor.to_string().is_empty()); - assert!(!v.patch.to_string().is_empty()); - assert!(!v.pre.to_string().is_empty()); + assert!(!v.major.to_string().is_empty()); + assert!(!v.minor.to_string().is_empty()); + assert!(!v.patch.to_string().is_empty()); + assert!(!v.pre.to_string().is_empty()); } }