From da96795303f608a1e7610362043ae951d1c2cc06 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Tue, 17 Mar 2026 09:41:46 +0800 Subject: [PATCH] refactor: make Clippy happy --- Cargo.lock | 4 ++-- yazi-actor/src/app/accept_payload.rs | 2 +- yazi-actor/src/app/mouse.rs | 2 +- yazi-actor/src/app/plugin_do.rs | 2 +- yazi-actor/src/app/reflow.rs | 2 +- yazi-binding/src/fd.rs | 2 +- yazi-binding/src/runtime.rs | 12 +++--------- yazi-fm/src/signals.rs | 6 ++---- yazi-plugin/src/lua.rs | 2 +- yazi-plugin/src/utils/log.rs | 2 +- yazi-plugin/src/utils/sync.rs | 2 +- yazi-scheduler/src/preload/preload.rs | 2 +- yazi-shared/src/data/data.rs | 4 ++-- yazi-shared/src/event/cow.rs | 2 +- yazi-widgets/src/clear.rs | 2 +- .../input/{commands/commands.rs => actor/actor.rs} | 0 .../src/input/{commands => actor}/backspace.rs | 0 .../src/input/{commands => actor}/backward.rs | 0 yazi-widgets/src/input/{commands => actor}/casefy.rs | 0 .../src/input/{commands => actor}/complete.rs | 0 yazi-widgets/src/input/{commands => actor}/delete.rs | 0 yazi-widgets/src/input/{commands => actor}/escape.rs | 0 .../src/input/{commands => actor}/forward.rs | 0 yazi-widgets/src/input/{commands => actor}/insert.rs | 0 yazi-widgets/src/input/{commands => actor}/kill.rs | 0 yazi-widgets/src/input/actor/mod.rs | 1 + yazi-widgets/src/input/{commands => actor}/move.rs | 0 yazi-widgets/src/input/{commands => actor}/paste.rs | 0 yazi-widgets/src/input/{commands => actor}/redo.rs | 0 .../src/input/{commands => actor}/replace.rs | 0 yazi-widgets/src/input/{commands => actor}/type.rs | 0 yazi-widgets/src/input/{commands => actor}/undo.rs | 0 yazi-widgets/src/input/{commands => actor}/visual.rs | 0 yazi-widgets/src/input/{commands => actor}/yank.rs | 0 yazi-widgets/src/input/commands/mod.rs | 1 - yazi-widgets/src/input/mod.rs | 2 +- yazi-widgets/src/input/widget.rs | 2 +- 37 files changed, 23 insertions(+), 31 deletions(-) rename yazi-widgets/src/input/{commands/commands.rs => actor/actor.rs} (100%) rename yazi-widgets/src/input/{commands => actor}/backspace.rs (100%) rename yazi-widgets/src/input/{commands => actor}/backward.rs (100%) rename yazi-widgets/src/input/{commands => actor}/casefy.rs (100%) rename yazi-widgets/src/input/{commands => actor}/complete.rs (100%) rename yazi-widgets/src/input/{commands => actor}/delete.rs (100%) rename yazi-widgets/src/input/{commands => actor}/escape.rs (100%) rename yazi-widgets/src/input/{commands => actor}/forward.rs (100%) rename yazi-widgets/src/input/{commands => actor}/insert.rs (100%) rename yazi-widgets/src/input/{commands => actor}/kill.rs (100%) create mode 100644 yazi-widgets/src/input/actor/mod.rs rename yazi-widgets/src/input/{commands => actor}/move.rs (100%) rename yazi-widgets/src/input/{commands => actor}/paste.rs (100%) rename yazi-widgets/src/input/{commands => actor}/redo.rs (100%) rename yazi-widgets/src/input/{commands => actor}/replace.rs (100%) rename yazi-widgets/src/input/{commands => actor}/type.rs (100%) rename yazi-widgets/src/input/{commands => actor}/undo.rs (100%) rename yazi-widgets/src/input/{commands => actor}/visual.rs (100%) rename yazi-widgets/src/input/{commands => actor}/yank.rs (100%) delete mode 100644 yazi-widgets/src/input/commands/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 67855409..bca5df10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2036,9 +2036,9 @@ dependencies = [ [[package]] name = "instability" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357b7205c6cd18dd2c86ed312d1e70add149aea98e7ef72b9fdf0270e555c11d" +checksum = "5eb2d60ef19920a3a9193c3e371f726ec1dafc045dac788d0fb3704272458971" dependencies = [ "darling 0.23.0", "indoc", diff --git a/yazi-actor/src/app/accept_payload.rs b/yazi-actor/src/app/accept_payload.rs index d125d046..1efe777c 100644 --- a/yazi-actor/src/app/accept_payload.rs +++ b/yazi-actor/src/app/accept_payload.rs @@ -29,7 +29,7 @@ impl Actor for AcceptPayload { drop(lock); let kind = kind.to_owned(); - succ!(Lives::scope(&cx.core, || { + succ!(Lives::scope(cx.core, || { let body = payload.body.into_lua(&LUA)?; for (id, cb) in handlers { if let Err(e) = runtime_scope!(LUA, &id, cb.call::<()>(body.clone())) { diff --git a/yazi-actor/src/app/mouse.rs b/yazi-actor/src/app/mouse.rs index 6db836d2..4368b1dd 100644 --- a/yazi-actor/src/app/mouse.rs +++ b/yazi-actor/src/app/mouse.rs @@ -25,7 +25,7 @@ impl Actor for Mouse { let Some(size) = cx.term.as_ref().and_then(|t| t.size().ok()) else { succ!() }; let area = yazi_binding::elements::Rect::from(size); - let result = Lives::scope(&cx.core, move || { + let result = Lives::scope(cx.core, move || { let root = runtime_scope!(LUA, "root", { LUA.globals().raw_get::("Root")?.call_method::
("new", area) })?; diff --git a/yazi-actor/src/app/plugin_do.rs b/yazi-actor/src/app/plugin_do.rs index e2f6ee3b..5c29c281 100644 --- a/yazi-actor/src/app/plugin_do.rs +++ b/yazi-actor/src/app/plugin_do.rs @@ -42,7 +42,7 @@ impl Actor for PluginDo { }; drop(loader); - let result = Lives::scope(&cx.core, || { + let result = Lives::scope(cx.core, || { if let Some(cb) = opt.callback { cb(&LUA, plugin) } else { diff --git a/yazi-actor/src/app/reflow.rs b/yazi-actor/src/app/reflow.rs index 129bc2a3..6ee1c80e 100644 --- a/yazi-actor/src/app/reflow.rs +++ b/yazi-actor/src/app/reflow.rs @@ -21,7 +21,7 @@ impl Actor for Reflow { let Some(size) = cx.term.as_ref().and_then(|t| t.size().ok()) else { succ!() }; let mut layout = LAYOUT.get(); - let result = Lives::scope(&cx.core, || { + let result = Lives::scope(cx.core, || { let comps = (opt.reflow)((Position::ORIGIN, size).into())?; for v in comps.sequence_values::() { diff --git a/yazi-binding/src/fd.rs b/yazi-binding/src/fd.rs index 0c1650ef..931329a7 100644 --- a/yazi-binding/src/fd.rs +++ b/yazi-binding/src/fd.rs @@ -24,7 +24,7 @@ impl UserData for Fd { } }); methods.add_async_method_mut("write_all", |lua, mut me, src: mlua::String| async move { - match me.0.write_all(&*src.as_bytes()).await { + match me.0.write_all(&src.as_bytes()).await { Ok(()) => true.into_lua_multi(&lua), Err(e) => (false, Error::Io(e)).into_lua_multi(&lua), } diff --git a/yazi-binding/src/runtime.rs b/yazi-binding/src/runtime.rs index 0301c1cb..a8c6ce43 100644 --- a/yazi-binding/src/runtime.rs +++ b/yazi-binding/src/runtime.rs @@ -4,7 +4,7 @@ use anyhow::{Context, Result}; use hashbrown::{HashMap, hash_map::EntryRef}; use mlua::Function; -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Runtime { frames: VecDeque, blocks: HashMap>, @@ -17,14 +17,8 @@ pub struct RuntimeFrame { } impl Runtime { - pub fn new() -> Self { Self { frames: <_>::default(), blocks: <_>::default(), blocking: false } } - pub fn new_isolate(id: &str) -> Self { - Self { - frames: VecDeque::from([RuntimeFrame { id: id.to_owned() }]), - blocks: <_>::default(), - blocking: false, - } + Self { frames: VecDeque::from([RuntimeFrame { id: id.to_owned() }]), ..Default::default() } } pub fn push(&mut self, id: &str) { self.frames.push_back(RuntimeFrame { id: id.to_owned() }); } @@ -54,7 +48,7 @@ impl Runtime { } pub fn put_block(&mut self, f: &Function) -> Option { - let Some(cur) = self.frames.back().filter(|f| f.id != "init") else { return None }; + let cur = self.frames.back().filter(|f| f.id != "init")?; Some(match self.blocks.entry_ref(&cur.id) { EntryRef::Occupied(mut oe) => { oe.get_mut().push(f.clone()); diff --git a/yazi-fm/src/signals.rs b/yazi-fm/src/signals.rs index bcb2d35c..6fe2641b 100644 --- a/yazi-fm/src/signals.rs +++ b/yazi-fm/src/signals.rs @@ -54,10 +54,8 @@ impl Signals { CrosstermEvent::Key(key @ KeyEvent { kind: KeyEventKind::Press, .. }) => { Event::Key(key).emit() } - CrosstermEvent::Mouse(mouse) => { - if YAZI.mgr.mouse_events.get().contains(mouse.kind.into()) { - Event::Mouse(mouse).emit(); - } + CrosstermEvent::Mouse(mouse) if YAZI.mgr.mouse_events.get().contains(mouse.kind.into()) => { + Event::Mouse(mouse).emit() } CrosstermEvent::Resize(..) => Event::Resize.emit(), CrosstermEvent::FocusGained => Event::Focus.emit(), diff --git a/yazi-plugin/src/lua.rs b/yazi-plugin/src/lua.rs index 00840a82..c8a2b034 100644 --- a/yazi-plugin/src/lua.rs +++ b/yazi-plugin/src/lua.rs @@ -17,7 +17,7 @@ pub(super) fn init_lua() -> Result<()> { } fn stage_1(lua: &'static Lua) -> Result<()> { - lua.set_app_data(Runtime::new()); + lua.set_app_data(Runtime::default()); // Base let globals = lua.globals(); diff --git a/yazi-plugin/src/utils/log.rs b/yazi-plugin/src/utils/log.rs index f46fdc72..b45bf127 100644 --- a/yazi-plugin/src/utils/log.rs +++ b/yazi-plugin/src/utils/log.rs @@ -20,7 +20,7 @@ impl Utils { if !s.is_empty() { s.push(' '); } - Utils::format_one(&mut s, value)?; + Self::format_one(&mut s, value)?; } Ok(s) } diff --git a/yazi-plugin/src/utils/sync.rs b/yazi-plugin/src/utils/sync.rs index d6b7ed54..f149546d 100644 --- a/yazi-plugin/src/utils/sync.rs +++ b/yazi-plugin/src/utils/sync.rs @@ -20,7 +20,7 @@ impl Utils { async move { loop { let values: MultiValue = thread.resume(args)?; - if let Some(Value::LightUserData(ud)) = values.get(0) + if let Some(Value::LightUserData(ud)) = values.front() && *ud == Lua::poll_pending() { args = lua.yield_with(values).await?; diff --git a/yazi-scheduler/src/preload/preload.rs b/yazi-scheduler/src/preload/preload.rs index ba96e63f..bf074b39 100644 --- a/yazi-scheduler/src/preload/preload.rs +++ b/yazi-scheduler/src/preload/preload.rs @@ -62,6 +62,6 @@ impl Preload { Priority::High => HIGH, }; - _ = self.tx.try_send(r#in.into(), priority); + _ = self.tx.try_send(r#in, priority); } } diff --git a/yazi-shared/src/data/data.rs b/yazi-shared/src/data/data.rs index 739a054b..4453c0e4 100644 --- a/yazi-shared/src/data/data.rs +++ b/yazi-shared/src/data/data.rs @@ -185,7 +185,7 @@ impl TryFrom for StrandBuf { Ok(match value { Data::String(s) => s.into_owned().into(), Data::Path(p) => p.into_strand(), - Data::Bytes(b) => StrandBuf::Bytes(b), + Data::Bytes(b) => Self::Bytes(b), _ => bail!("cannot convert to StrandBuf"), }) } @@ -198,7 +198,7 @@ impl TryFrom<&Data> for StrandBuf { Ok(match value { Data::String(s) => s.to_string().into(), Data::Path(p) => p.into_strand(), - Data::Bytes(b) => StrandBuf::Bytes(b.clone()), + Data::Bytes(b) => Self::Bytes(b.clone()), _ => bail!("cannot convert to StrandBuf"), }) } diff --git a/yazi-shared/src/event/cow.rs b/yazi-shared/src/event/cow.rs index 04af09de..2f6c7314 100644 --- a/yazi-shared/src/event/cow.rs +++ b/yazi-shared/src/event/cow.rs @@ -23,7 +23,7 @@ impl Deref for ActionCow { } impl From for () { - fn from(_: ActionCow) -> Self { () } + fn from(_: ActionCow) -> Self {} } impl From for ActionCow { diff --git a/yazi-widgets/src/clear.rs b/yazi-widgets/src/clear.rs index 807a3136..805706ca 100644 --- a/yazi-widgets/src/clear.rs +++ b/yazi-widgets/src/clear.rs @@ -5,7 +5,7 @@ use yazi_adapter::ADAPTOR; pub static COLLISION: AtomicBool = AtomicBool::new(false); -#[derive(Clone, Copy, Debug, Default)] +#[derive(Clone, Copy, Debug)] pub struct Clear; impl Widget for Clear { diff --git a/yazi-widgets/src/input/commands/commands.rs b/yazi-widgets/src/input/actor/actor.rs similarity index 100% rename from yazi-widgets/src/input/commands/commands.rs rename to yazi-widgets/src/input/actor/actor.rs diff --git a/yazi-widgets/src/input/commands/backspace.rs b/yazi-widgets/src/input/actor/backspace.rs similarity index 100% rename from yazi-widgets/src/input/commands/backspace.rs rename to yazi-widgets/src/input/actor/backspace.rs diff --git a/yazi-widgets/src/input/commands/backward.rs b/yazi-widgets/src/input/actor/backward.rs similarity index 100% rename from yazi-widgets/src/input/commands/backward.rs rename to yazi-widgets/src/input/actor/backward.rs diff --git a/yazi-widgets/src/input/commands/casefy.rs b/yazi-widgets/src/input/actor/casefy.rs similarity index 100% rename from yazi-widgets/src/input/commands/casefy.rs rename to yazi-widgets/src/input/actor/casefy.rs diff --git a/yazi-widgets/src/input/commands/complete.rs b/yazi-widgets/src/input/actor/complete.rs similarity index 100% rename from yazi-widgets/src/input/commands/complete.rs rename to yazi-widgets/src/input/actor/complete.rs diff --git a/yazi-widgets/src/input/commands/delete.rs b/yazi-widgets/src/input/actor/delete.rs similarity index 100% rename from yazi-widgets/src/input/commands/delete.rs rename to yazi-widgets/src/input/actor/delete.rs diff --git a/yazi-widgets/src/input/commands/escape.rs b/yazi-widgets/src/input/actor/escape.rs similarity index 100% rename from yazi-widgets/src/input/commands/escape.rs rename to yazi-widgets/src/input/actor/escape.rs diff --git a/yazi-widgets/src/input/commands/forward.rs b/yazi-widgets/src/input/actor/forward.rs similarity index 100% rename from yazi-widgets/src/input/commands/forward.rs rename to yazi-widgets/src/input/actor/forward.rs diff --git a/yazi-widgets/src/input/commands/insert.rs b/yazi-widgets/src/input/actor/insert.rs similarity index 100% rename from yazi-widgets/src/input/commands/insert.rs rename to yazi-widgets/src/input/actor/insert.rs diff --git a/yazi-widgets/src/input/commands/kill.rs b/yazi-widgets/src/input/actor/kill.rs similarity index 100% rename from yazi-widgets/src/input/commands/kill.rs rename to yazi-widgets/src/input/actor/kill.rs diff --git a/yazi-widgets/src/input/actor/mod.rs b/yazi-widgets/src/input/actor/mod.rs new file mode 100644 index 00000000..7913df7d --- /dev/null +++ b/yazi-widgets/src/input/actor/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(actor backspace backward casefy complete delete escape forward insert kill paste r#move r#type redo replace undo visual yank); diff --git a/yazi-widgets/src/input/commands/move.rs b/yazi-widgets/src/input/actor/move.rs similarity index 100% rename from yazi-widgets/src/input/commands/move.rs rename to yazi-widgets/src/input/actor/move.rs diff --git a/yazi-widgets/src/input/commands/paste.rs b/yazi-widgets/src/input/actor/paste.rs similarity index 100% rename from yazi-widgets/src/input/commands/paste.rs rename to yazi-widgets/src/input/actor/paste.rs diff --git a/yazi-widgets/src/input/commands/redo.rs b/yazi-widgets/src/input/actor/redo.rs similarity index 100% rename from yazi-widgets/src/input/commands/redo.rs rename to yazi-widgets/src/input/actor/redo.rs diff --git a/yazi-widgets/src/input/commands/replace.rs b/yazi-widgets/src/input/actor/replace.rs similarity index 100% rename from yazi-widgets/src/input/commands/replace.rs rename to yazi-widgets/src/input/actor/replace.rs diff --git a/yazi-widgets/src/input/commands/type.rs b/yazi-widgets/src/input/actor/type.rs similarity index 100% rename from yazi-widgets/src/input/commands/type.rs rename to yazi-widgets/src/input/actor/type.rs diff --git a/yazi-widgets/src/input/commands/undo.rs b/yazi-widgets/src/input/actor/undo.rs similarity index 100% rename from yazi-widgets/src/input/commands/undo.rs rename to yazi-widgets/src/input/actor/undo.rs diff --git a/yazi-widgets/src/input/commands/visual.rs b/yazi-widgets/src/input/actor/visual.rs similarity index 100% rename from yazi-widgets/src/input/commands/visual.rs rename to yazi-widgets/src/input/actor/visual.rs diff --git a/yazi-widgets/src/input/commands/yank.rs b/yazi-widgets/src/input/actor/yank.rs similarity index 100% rename from yazi-widgets/src/input/commands/yank.rs rename to yazi-widgets/src/input/actor/yank.rs diff --git a/yazi-widgets/src/input/commands/mod.rs b/yazi-widgets/src/input/commands/mod.rs deleted file mode 100644 index 8e01d1f5..00000000 --- a/yazi-widgets/src/input/commands/mod.rs +++ /dev/null @@ -1 +0,0 @@ -yazi_macro::mod_flat!(backspace backward casefy commands complete delete escape forward insert kill paste r#move r#type redo replace undo visual yank); diff --git a/yazi-widgets/src/input/mod.rs b/yazi-widgets/src/input/mod.rs index 46396771..a2c53152 100644 --- a/yazi-widgets/src/input/mod.rs +++ b/yazi-widgets/src/input/mod.rs @@ -1,3 +1,3 @@ -yazi_macro::mod_pub!(commands parser); +yazi_macro::mod_pub!(actor parser); yazi_macro::mod_flat!(error input mode op snap snaps widget); diff --git a/yazi-widgets/src/input/widget.rs b/yazi-widgets/src/input/widget.rs index 7f1e15ba..9a5f2a09 100644 --- a/yazi-widgets/src/input/widget.rs +++ b/yazi-widgets/src/input/widget.rs @@ -10,7 +10,7 @@ impl Widget for &Input { where Self: Sized, { - crate::Clear::default().render(area, buf); + crate::Clear.render(area, buf); Line::styled(self.display(), THEME.input.value).render(area, buf);