chore: update Rust to 2024 edition (#2066)

This commit is contained in:
Luna Yao
2026-04-09 18:22:12 +02:00
committed by GitHub
parent a8feb9ac2b
commit a879dd1b14
158 changed files with 1327 additions and 1231 deletions
@@ -57,17 +57,16 @@ impl Default for RollingConditionBase {
impl RollingCondition for RollingConditionBase {
fn should_rollover(&mut self, now: &DateTime<Local>, current_filesize: u64) -> bool {
let mut rollover = false;
if let Some(frequency) = self.frequency_opt.as_ref() {
if let Some(last_write) = self.last_write_opt.as_ref() {
if frequency.equivalent_datetime(now) != frequency.equivalent_datetime(last_write) {
rollover = true;
}
}
if let Some(frequency) = self.frequency_opt.as_ref()
&& let Some(last_write) = self.last_write_opt.as_ref()
&& frequency.equivalent_datetime(now) != frequency.equivalent_datetime(last_write)
{
rollover = true;
}
if let Some(max_size) = self.max_size_opt.as_ref() {
if current_filesize >= *max_size {
rollover = true;
}
if let Some(max_size) = self.max_size_opt.as_ref()
&& current_filesize >= *max_size
{
rollover = true;
}
self.last_write_opt = Some(*now);
rollover
@@ -81,11 +81,7 @@ where
/// Determines the final filename, where n==0 indicates the current file
fn filename_for(&self, n: usize) -> String {
let f = self.filename.clone();
if n > 0 {
format!("{}.{}", f, n)
} else {
f
}
if n > 0 { format!("{}.{}", f, n) } else { f }
}
/// Rotates old files to make room for a new one.
@@ -145,14 +141,14 @@ where
/// Writes data using the given datetime to calculate the rolling condition
pub fn write_with_datetime(&mut self, buf: &[u8], now: &DateTime<Local>) -> io::Result<usize> {
if self.condition.should_rollover(now, self.current_filesize) {
if let Err(e) = self.rollover() {
// If we can't rollover, just try to continue writing anyway
// (better than missing data).
// This will likely used to implement logging, so
// avoid using log::warn and log to stderr directly
eprintln!("WARNING: Failed to rotate logfile {}: {}", self.filename, e);
}
if self.condition.should_rollover(now, self.current_filesize)
&& let Err(e) = self.rollover()
{
// If we can't rollover, just try to continue writing anyway
// (better than missing data).
// This will likely used to implement logging, so
// avoid using log::warn and log to stderr directly
eprintln!("WARNING: Failed to rotate logfile {}: {}", self.filename, e);
}
self.open_writer_if_needed()?;
if let Some(writer) = self.writer_opt.as_mut() {