From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id EFB75B87A5; Tue, 5 Dec 2023 13:12:47 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C69201A313; Tue, 5 Dec 2023 13:12:17 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS; Tue, 5 Dec 2023 13:12:16 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 56CA544C65; Tue, 5 Dec 2023 13:12:16 +0100 (CET) From: Lukas Wagner To: pbs-devel@lists.proxmox.com, pve-devel@lists.proxmox.com Date: Tue, 5 Dec 2023 13:11:39 +0100 Message-Id: <20231205121142.169542-3-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231205121142.169542-1-l.wagner@proxmox.com> References: <20231205121142.169542-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.007 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [posix.rs] Subject: [pbs-devel] [PATCH proxmox 2/5] time: posix: inline vars in string formatting X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Dec 2023 12:12:48 -0000 No functional changes. Signed-off-by: Lukas Wagner --- proxmox-time/src/posix.rs | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/proxmox-time/src/posix.rs b/proxmox-time/src/posix.rs index c463ab3..5913816 100644 --- a/proxmox-time/src/posix.rs +++ b/proxmox-time/src/posix.rs @@ -13,7 +13,7 @@ pub fn timelocal(t: &mut libc::tm) -> Result { let epoch = unsafe { libc::mktime(t) }; if epoch == -1 { - bail!("libc::mktime failed for {:?}", t); + bail!("libc::mktime failed for {t:?}"); } Ok(epoch) } @@ -27,7 +27,7 @@ pub fn timegm(t: &mut libc::tm) -> Result { let epoch = unsafe { libc::timegm(t) }; if epoch == -1 { - bail!("libc::timegm failed for {:?}", t); + bail!("libc::timegm failed for {t:?}"); } Ok(epoch) } @@ -54,7 +54,7 @@ pub fn localtime(epoch: i64) -> Result { unsafe { if libc::localtime_r(&epoch, &mut result).is_null() { - bail!("libc::localtime failed for '{}'", epoch); + bail!("libc::localtime failed for '{epoch}'"); } } @@ -67,7 +67,7 @@ pub fn gmtime(epoch: i64) -> Result { unsafe { if libc::gmtime_r(&epoch, &mut result).is_null() { - bail!("libc::gmtime failed for '{}'", epoch); + bail!("libc::gmtime failed for '{epoch}'"); } } @@ -110,7 +110,7 @@ pub fn epoch_f64() -> f64 { /// Safe bindings to libc strftime pub fn strftime(format: &str, t: &libc::tm) -> Result { - let format = CString::new(format).map_err(|err| format_err!("{}", err))?; + let format = CString::new(format).map_err(|err| format_err!("{err}"))?; let mut buf = vec![0u8; 8192]; let res = unsafe { @@ -135,7 +135,7 @@ pub fn strftime(format: &str, t: &libc::tm) -> Result { bail!("strftime: result len is 0 (string too large)"); }; - let c_str = CStr::from_bytes_with_nul(&buf[..len + 1]).map_err(|err| format_err!("{}", err))?; + let c_str = CStr::from_bytes_with_nul(&buf[..len + 1]).map_err(|err| format_err!("{err}"))?; let str_slice: &str = c_str.to_str().unwrap(); Ok(str_slice.to_owned()) } @@ -158,7 +158,7 @@ pub fn epoch_to_rfc3339_utc(epoch: i64) -> Result { let year = gmtime.tm_year + 1900; if year < 0 || year > 9999 { - bail!("epoch_to_rfc3339_utc: wrong year '{}'", year); + bail!("epoch_to_rfc3339_utc: wrong year '{year}'"); } strftime("%010FT%TZ", &gmtime) @@ -172,7 +172,7 @@ pub fn epoch_to_rfc3339(epoch: i64) -> Result { let year = localtime.tm_year + 1900; if year < 0 || year > 9999 { - bail!("epoch_to_rfc3339: wrong year '{}'", year); + bail!("epoch_to_rfc3339: wrong year '{year}'"); } // Note: We cannot use strftime %z because of missing collon @@ -192,20 +192,15 @@ pub fn epoch_to_rfc3339(epoch: i64) -> Result { let mut s = strftime("%10FT%T", &localtime)?; s.push(prefix); - let _ = write!(s, "{:02}:{:02}", hours, mins); + let _ = write!(s, "{hours:02}:{mins:02}"); Ok(s) } /// Parse RFC3339 into Unix epoch pub fn parse_rfc3339(input_str: &str) -> Result { - parse_rfc3339_do(input_str).map_err(|err| { - format_err!( - "failed to parse rfc3339 timestamp ({:?}) - {}", - input_str, - err - ) - }) + parse_rfc3339_do(input_str) + .map_err(|err| format_err!("failed to parse rfc3339 timestamp ({input_str:?}) - {err}",)) } fn parse_rfc3339_do(input_str: &str) -> Result { @@ -213,7 +208,7 @@ fn parse_rfc3339_do(input_str: &str) -> Result { let expect = |pos: usize, c: u8| { if input[pos] != c { - bail!("unexpected char at pos {}", pos); + bail!("unexpected char at pos {pos}"); } Ok(()) }; @@ -221,14 +216,14 @@ fn parse_rfc3339_do(input_str: &str) -> Result { let digit = |pos: usize| -> Result { let digit = input[pos] as i32; if digit < 48 || digit > 57 { - bail!("unexpected char at pos {}", pos); + bail!("unexpected char at pos {pos}"); } Ok(digit - 48) }; fn check_max(i: i32, max: i32) -> Result { if i > max { - bail!("value too large ({} > {})", i, max); + bail!("value too large ({i} > {max})"); } Ok(i) } -- 2.39.2