From 4af79f8f4a86cc8099e982c52cede52a474d0445 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Thu, 3 Aug 2023 21:54:59 +0800 Subject: [PATCH] refactor: using string interpolation --- adaptor/src/sixel.rs | 8 ++++---- app/src/logs.rs | 2 +- app/src/manager/folder.rs | 2 +- app/src/select/select.rs | 4 ++-- app/src/status/left.rs | 2 +- config/src/keymap/key.rs | 2 +- config/src/manager/sorting.rs | 2 +- config/src/theme/color.rs | 2 +- core/src/manager/manager.rs | 2 +- core/src/manager/preview.rs | 2 +- core/src/tasks/scheduler.rs | 4 ++-- core/src/tasks/workers/file.rs | 8 ++++---- core/src/tasks/workers/process.rs | 2 +- shared/src/fns.rs | 2 +- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/adaptor/src/sixel.rs b/adaptor/src/sixel.rs index 4763094f..15714240 100644 --- a/adaptor/src/sixel.rs +++ b/adaptor/src/sixel.rs @@ -69,18 +69,18 @@ impl Sixel { } if repeat > 1 { - write!(buf, "#{}!{}{}", last, repeat, c)?; + write!(buf, "#{last}!{repeat}{c}")?; } else { - write!(buf, "#{}{}", last, c)?; + write!(buf, "#{last}{c}")?; } (last, repeat) = (idx, 1); } if repeat > 1 { - write!(buf, "#{}!{}{}", last, repeat, c)?; + write!(buf, "#{last}!{repeat}{c}")?; } else { - write!(buf, "#{}{}", last, c)?; + write!(buf, "#{last}{c}")?; } write!(buf, "$")?; diff --git a/app/src/logs.rs b/app/src/logs.rs index d45ced55..49604dd0 100644 --- a/app/src/logs.rs +++ b/app/src/logs.rs @@ -3,7 +3,7 @@ use config::LOG; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::{fmt, prelude::__tracing_subscriber_SubscriberExt, Registry}; -pub(super) struct Logs {} +pub(super) struct Logs; impl Logs { pub(super) fn init() -> Result { diff --git a/app/src/manager/folder.rs b/app/src/manager/folder.rs index 53738ca4..bd88cfbd 100644 --- a/app/src/manager/folder.rs +++ b/app/src/manager/folder.rs @@ -77,7 +77,7 @@ impl<'a> Widget for Folder<'a> { self.file_style(v) }; - ListItem::new(format!(" {} {}", icon, readable_path(k, &self.folder.cwd))).style(style) + ListItem::new(format!(" {icon} {}", readable_path(k, &self.folder.cwd))).style(style) }) .collect::>(); diff --git a/app/src/select/select.rs b/app/src/select/select.rs index a0f9a609..367f8596 100644 --- a/app/src/select/select.rs +++ b/app/src/select/select.rs @@ -21,10 +21,10 @@ impl<'a> Widget for Select<'a> { .enumerate() .map(|(i, v)| { if i != select.rel_cursor() { - return ListItem::new(format!(" {}", v)); + return ListItem::new(format!(" {v}")); } - ListItem::new(format!(" {}", v)).style(Style::new().fg(Color::Magenta)) + ListItem::new(format!(" {v}")).style(Style::new().fg(Color::Magenta)) }) .collect::>(); diff --git a/app/src/status/left.rs b/app/src/status/left.rs index b87fc180..6402ad4c 100644 --- a/app/src/status/left.rs +++ b/app/src/status/left.rs @@ -27,7 +27,7 @@ impl<'a> Widget for Left<'a> { // Mode spans.push(Span::styled("", primary.fg())); spans.push(Span::styled( - format!(" {} ", mode), + format!(" {mode} "), primary.bg().fg(**secondary).add_modifier(Modifier::BOLD), )); diff --git a/config/src/keymap/key.rs b/config/src/keymap/key.rs index a9b59afe..ad22fec2 100644 --- a/config/src/keymap/key.rs +++ b/config/src/keymap/key.rs @@ -92,7 +92,7 @@ impl TryFrom for Key { c if it.peek().is_none() => { key.code = KeyCode::Char(c.chars().next().unwrap()); } - k => bail!("unknown key: {}", k), + k => bail!("unknown key: {k}"), } } diff --git a/config/src/manager/sorting.rs b/config/src/manager/sorting.rs index f342cb40..8c0010e5 100644 --- a/config/src/manager/sorting.rs +++ b/config/src/manager/sorting.rs @@ -20,7 +20,7 @@ impl TryFrom for SortBy { "created" => Self::Created, "modified" => Self::Modified, "size" => Self::Size, - _ => bail!("invalid sort_by value: {}", s), + _ => bail!("invalid sort_by value: {s}"), }) } } diff --git a/config/src/theme/color.rs b/config/src/theme/color.rs index 4b3dc32b..8bf85221 100644 --- a/config/src/theme/color.rs +++ b/config/src/theme/color.rs @@ -17,7 +17,7 @@ impl TryFrom for Color { fn try_from(s: String) -> Result { if s.len() < 7 { - bail!("Invalid color: {}", s); + bail!("Invalid color: {s}"); } Ok(Self(style::Color::Rgb( u8::from_str_radix(&s[1..3], 16)?, diff --git a/core/src/manager/manager.rs b/core/src/manager/manager.rs index 744a4a9b..6b76dc3b 100644 --- a/core/src/manager/manager.rs +++ b/core/src/manager/manager.rs @@ -99,7 +99,7 @@ impl Manager { tokio::spawn(async move { let result = emit!(Input(InputOpt { - title: format!("There are {} tasks running, sure to quit? (y/N)", tasks), + title: format!("There are {tasks} tasks running, sure to quit? (y/N)"), value: "".to_string(), position: Position::Top, })); diff --git a/core/src/manager/preview.rs b/core/src/manager/preview.rs index b634cb12..fe2faeb5 100644 --- a/core/src/manager/preview.rs +++ b/core/src/manager/preview.rs @@ -65,7 +65,7 @@ impl Preview { MimeKind::Image => Self::image(&path).await, MimeKind::Video => Self::video(&path).await, MimeKind::Archive => Self::archive(&path).await.map(PreviewData::Text), - MimeKind::Others => Err(anyhow!("Unsupported mimetype: {}", mime)), + MimeKind::Others => Err(anyhow!("Unsupported mimetype: {mime}")), }; emit!(Preview(path, mime, result.unwrap_or_default())); diff --git a/core/src/tasks/scheduler.rs b/core/src/tasks/scheduler.rs index 54d2fc95..9deeca50 100644 --- a/core/src/tasks/scheduler.rs +++ b/core/src/tasks/scheduler.rs @@ -76,7 +76,7 @@ impl Scheduler { continue; } if let Err(e) = file.work(&mut op).await { - info!("Failed to work on task {:?}: {}", op, e); + info!("Failed to work on task {:?}: {e}", op); } else { trace!("Finished task {:?}", op); } @@ -87,7 +87,7 @@ impl Scheduler { continue; } if let Err(e) = precache.work(&mut op).await { - info!("Failed to work on task {:?}: {}", op, e); + info!("Failed to work on task {:?}: {e}", op); } else { trace!("Finished task {:?}", op); } diff --git a/core/src/tasks/workers/file.rs b/core/src/tasks/workers/file.rs index d3aa5aa0..fce5dfbf 100644 --- a/core/src/tasks/workers/file.rs +++ b/core/src/tasks/workers/file.rs @@ -90,7 +90,7 @@ impl File { break; } Ok(n) => { - self.log(task.id, format!("Paste task advanced {}: {:?}", n, task))?; + self.log(task.id, format!("Paste task advanced {n}: {:?}", task))?; self.sch.send(TaskOp::Adv(task.id, 0, n))? } Err(e) if e.kind() == NotFound => { @@ -132,7 +132,7 @@ impl File { FileOp::Delete(task) => { if let Err(e) = fs::remove_file(&task.target).await { if e.kind() != NotFound && fs::symlink_metadata(&task.target).await.is_ok() { - self.log(task.id, format!("Delete task failed: {:?}, {}", task, e))?; + self.log(task.id, format!("Delete task failed: {:?}, {e}", task))?; Err(e)? } } @@ -192,7 +192,7 @@ impl File { let dest = root.join(src.components().skip(skip).collect::()); match fs::create_dir(&dest).await { Err(e) if e.kind() != AlreadyExists => { - self.log(task.id, format!("Create dir failed: {:?}, {}", dest, e))?; + self.log(task.id, format!("Create dir failed: {:?}, {e}", dest))?; continue; } _ => {} @@ -201,7 +201,7 @@ impl File { let mut it = match fs::read_dir(&src).await { Ok(it) => it, Err(e) => { - self.log(task.id, format!("Read dir failed: {:?}, {}", src, e))?; + self.log(task.id, format!("Read dir failed: {:?}, {e}", src))?; continue; } }; diff --git a/core/src/tasks/workers/process.rs b/core/src/tasks/workers/process.rs index cde99ba5..12753ced 100644 --- a/core/src/tasks/workers/process.rs +++ b/core/src/tasks/workers/process.rs @@ -38,7 +38,7 @@ impl Process { child.wait().await.ok(); } Err(e) => { - trace!("Failed to spawn {}: {}", task.cmd, e); + trace!("Failed to spawn {}: {e}", task.cmd); } } diff --git a/shared/src/fns.rs b/shared/src/fns.rs index 81fa6045..e607c9de 100644 --- a/shared/src/fns.rs +++ b/shared/src/fns.rs @@ -53,7 +53,7 @@ pub async fn unique_path(mut p: PathBuf) -> PathBuf { while fs::symlink_metadata(&p).await.is_ok() { i += 1; let mut name = name.clone(); - name.push(format!("_{}", i)); + name.push(format!("_{i}")); p.set_file_name(name); } p