From a19b8c2e24c951909dcf92f6b7bd9aa964867499 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Wed, 25 May 2022 18:26:52 +0200 Subject: [PATCH] pbs-config: clippy fixes Signed-off-by: Thomas Lamprecht --- pbs-config/src/datastore.rs | 10 +++++----- pbs-config/src/key_config.rs | 8 ++++---- pbs-config/src/network/helper.rs | 4 ++-- pbs-config/src/network/parser.rs | 4 ++-- pbs-config/src/verify.rs | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pbs-config/src/datastore.rs b/pbs-config/src/datastore.rs index d3fd9947..b2b4d2a0 100644 --- a/pbs-config/src/datastore.rs +++ b/pbs-config/src/datastore.rs @@ -67,11 +67,11 @@ pub fn complete_datastore_name(_arg: &str, _param: &HashMap) -> } pub fn complete_acl_path(_arg: &str, _param: &HashMap) -> Vec { - let mut list = Vec::new(); - - list.push(String::from("/")); - list.push(String::from("/datastore")); - list.push(String::from("/datastore/")); + let mut list = vec![ + String::from("/"), + String::from("/datastore"), + String::from("/datastore/"), + ]; if let Ok((data, _digest)) = config() { for id in data.sections.keys() { diff --git a/pbs-config/src/key_config.rs b/pbs-config/src/key_config.rs index 1cf6b7c2..6186b57c 100644 --- a/pbs-config/src/key_config.rs +++ b/pbs-config/src/key_config.rs @@ -370,8 +370,8 @@ fn fingerprint_checks() -> Result<(), Error> { 131, 185, 101, 156, 10, 87, 174, 25, 144, 144, 21, 155, ]); - let mut data = serde_json::to_vec(&key).expect("encoding KeyConfig failed"); - decrypt_key(&mut data, &{ || Ok(Vec::new()) }) + let data = serde_json::to_vec(&key).expect("encoding KeyConfig failed"); + decrypt_key(&data, &{ || Ok(Vec::new()) }) .expect_err("decoding KeyConfig with wrong fingerprint worked"); let key = KeyConfig { @@ -383,8 +383,8 @@ fn fingerprint_checks() -> Result<(), Error> { hint: None, }; - let mut data = serde_json::to_vec(&key).expect("encoding KeyConfig failed"); - let (key_data, created, fingerprint) = decrypt_key(&mut data, &{ || Ok(Vec::new()) }) + let data = serde_json::to_vec(&key).expect("encoding KeyConfig failed"); + let (key_data, created, fingerprint) = decrypt_key(&data, &{ || Ok(Vec::new()) }) .expect("decoding KeyConfig without fingerprint failed"); assert_eq!(key.data, key_data); diff --git a/pbs-config/src/network/helper.rs b/pbs-config/src/network/helper.rs index 7bf7e966..e335ba25 100644 --- a/pbs-config/src/network/helper.rs +++ b/pbs-config/src/network/helper.rs @@ -101,7 +101,7 @@ pub fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option, bool), E if let Some(caps) = CIDR_V4_REGEX.captures(cidr) { let address = &caps[1]; if let Some(mask) = caps.get(2) { - let mask = u8::from_str_radix(mask.as_str(), 10)?; + let mask: u8 = mask.as_str().parse()?; check_netmask(mask, false)?; Ok((address.to_string(), Some(mask), false)) } else { @@ -110,7 +110,7 @@ pub fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option, bool), E } else if let Some(caps) = CIDR_V6_REGEX.captures(cidr) { let address = &caps[1]; if let Some(mask) = caps.get(2) { - let mask = u8::from_str_radix(mask.as_str(), 10)?; + let mask: u8 = mask.as_str().parse()?; check_netmask(mask, true)?; Ok((address.to_string(), Some(mask), true)) } else { diff --git a/pbs-config/src/network/parser.rs b/pbs-config/src/network/parser.rs index 78a92ebc..e53543ba 100644 --- a/pbs-config/src/network/parser.rs +++ b/pbs-config/src/network/parser.rs @@ -164,7 +164,7 @@ impl NetworkParser { let mask = if let Some(mask) = IPV4_MASK_HASH_LOCALNET.get(netmask.as_str()) { *mask } else { - match u8::from_str_radix(netmask.as_str(), 10) { + match netmask.as_str().parse::() { Ok(mask) => mask, Err(err) => { bail!("unable to parse netmask '{}' - {}", netmask, err); @@ -211,7 +211,7 @@ impl NetworkParser { self.eat(Token::MTU)?; let mtu = self.next_text()?; - let mtu = match u64::from_str_radix(&mtu, 10) { + let mtu = match mtu.parse::() { Ok(mtu) => mtu, Err(err) => { bail!("unable to parse mtu value '{}' - {}", mtu, err); diff --git a/pbs-config/src/verify.rs b/pbs-config/src/verify.rs index 6f762617..84cec732 100644 --- a/pbs-config/src/verify.rs +++ b/pbs-config/src/verify.rs @@ -41,7 +41,7 @@ pub fn lock_config() -> Result { pub fn config() -> Result<(SectionConfigData, [u8; 32]), Error> { let content = proxmox_sys::fs::file_read_optional_string(VERIFICATION_CFG_FILENAME)?; - let content = content.unwrap_or_else(String::new); + let content = content.unwrap_or_default(); let digest = openssl::sha::sha256(content.as_bytes()); let data = CONFIG.parse(VERIFICATION_CFG_FILENAME, &content)?; -- 2.39.5