diff --git a/Cargo.lock b/Cargo.lock index d7d4c172..3d25ad41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,9 +193,9 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" [[package]] name = "cc" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c6b2562119bf28c3439f7f02db99faf0aa1a8cdfe5772a2ee155d32227239f0" +checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" dependencies = [ "libc", ] @@ -705,9 +705,9 @@ dependencies = [ [[package]] name = "image" -version = "0.24.6" +version = "0.24.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527909aa81e20ac3a44803521443a765550f09b5130c2c2fa1ea59c2f8f50a3a" +checksum = "6f3dfdbdd72063086ff443e297b61695500514b1e41095b6fb9a5ab48a70a711" dependencies = [ "bytemuck", "byteorder", @@ -1283,18 +1283,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.182" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdb30a74471f5b7a1fa299f40b4bf1be93af61116df95465b2b5fc419331e430" +checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.182" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f4c2c6ea4bc09b5c419012eafcdb0fcef1d9119d626c8f3a0708a5b92d38a70" +checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" dependencies = [ "proc-macro2", "quote", @@ -1488,9 +1488,9 @@ dependencies = [ [[package]] name = "tiff" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7449334f9ff2baf290d55d73983a7d6fa15e01198faef72af07e2a8db851e471" +checksum = "6d172b0f4d3fba17ba89811858b9d3d97f928aece846475bbda076ca46736211" dependencies = [ "flate2", "jpeg-decoder", diff --git a/adaptor/src/adaptor.rs b/adaptor/src/adaptor.rs index f5a96de0..1604fdae 100644 --- a/adaptor/src/adaptor.rs +++ b/adaptor/src/adaptor.rs @@ -11,6 +11,7 @@ use crate::{Image, Sixel}; static IMAGE_SHOWN: AtomicBool = AtomicBool::new(false); +#[allow(clippy::type_complexity)] static UEBERZUG: Lazy>>> = Lazy::new(|| if PREVIEW.adaptor.needs_ueberzug() { Ueberzug::start().ok() } else { None }); diff --git a/adaptor/src/lib.rs b/adaptor/src/lib.rs index 8bf2d3c1..8e6f2bdc 100644 --- a/adaptor/src/lib.rs +++ b/adaptor/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unit_arg)] + mod adaptor; mod image; mod iterm2; @@ -5,9 +7,9 @@ mod kitty; mod sixel; mod ueberzug; -pub use crate::adaptor::*; -pub use crate::image::*; -pub(self) use iterm2::*; -pub(self) use kitty::*; -pub(self) use sixel::*; -pub(self) use ueberzug::*; +use iterm2::*; +use kitty::*; +use sixel::*; +use ueberzug::*; + +pub use crate::{adaptor::*, image::*}; diff --git a/adaptor/src/sixel.rs b/adaptor/src/sixel.rs index 15714240..5a733f4e 100644 --- a/adaptor/src/sixel.rs +++ b/adaptor/src/sixel.rs @@ -55,7 +55,7 @@ impl Sixel { } for y in 0..img.height() { - let c = (b'?' + (1 << (y % 6))) as u8 as char; + let c = (b'?' + (1 << (y % 6))) as char; let mut last = 0; let mut repeat = 0usize; diff --git a/app/src/app.rs b/app/src/app.rs index cd0993d2..2bb3e21f 100644 --- a/app/src/app.rs +++ b/app/src/app.rs @@ -56,7 +56,7 @@ impl App { fn dispatch_render(&mut self) { if let Some(term) = &mut self.term { let _ = term.draw(|f| { - f.render_widget(Root::new(&mut self.cx), f.size()); + f.render_widget(Root::new(&self.cx), f.size()); if let Some((x, y)) = self.cx.cursor() { f.set_cursor(x, y); diff --git a/app/src/context.rs b/app/src/context.rs index 3c047e5c..18dc162f 100644 --- a/app/src/context.rs +++ b/app/src/context.rs @@ -14,7 +14,7 @@ pub struct Ctx { impl Ctx { pub(super) fn new() -> Self { Self { - manager: Manager::new(), + manager: Manager::make(), which: Default::default(), select: Default::default(), input: Default::default(), @@ -47,11 +47,7 @@ impl Ctx { #[inline] pub(super) fn image_layer(&self) -> bool { - match self.layer() { - KeymapLayer::Which => false, - KeymapLayer::Tasks => false, - _ => true, - } + !matches!(self.layer(), KeymapLayer::Which | KeymapLayer::Tasks) } pub(super) fn position(&self, pos: Position) -> Position { diff --git a/app/src/executor.rs b/app/src/executor.rs index 5bbc8b48..7eea35b3 100644 --- a/app/src/executor.rs +++ b/app/src/executor.rs @@ -66,7 +66,7 @@ impl Executor { "back" => cx.manager.active_mut().back(), "forward" => cx.manager.active_mut().forward(), "cd" => { - let path = exec.args.get(0).map(|s| PathBuf::from(s)).unwrap_or_default(); + let path = exec.args.get(0).map(PathBuf::from).unwrap_or_default(); emit!(Cd(path)); false } @@ -182,7 +182,7 @@ impl Executor { "arrow" => { let step: isize = exec.args.get(0).and_then(|s| s.parse().ok()).unwrap_or(0); - if step > 0 { cx.select.next(step as usize) } else { cx.select.prev(step.abs() as usize) } + if step > 0 { cx.select.next(step as usize) } else { cx.select.prev(step.unsigned_abs()) } } _ => false, diff --git a/app/src/header/layout.rs b/app/src/header/layout.rs index 60978d01..a704bf4f 100644 --- a/app/src/header/layout.rs +++ b/app/src/header/layout.rs @@ -23,7 +23,7 @@ impl<'a> Widget for Layout<'a> { let location = if current.in_search { format!("{} (search)", readable_home(¤t.cwd)) } else { - format!("{}", readable_home(¤t.cwd)) + readable_home(¤t.cwd) }; Paragraph::new(location).style(Style::new().fg(Color::Cyan)).render(chunks[0], buf); diff --git a/app/src/header/mod.rs b/app/src/header/mod.rs index 6587c464..bf8f0116 100644 --- a/app/src/header/mod.rs +++ b/app/src/header/mod.rs @@ -2,4 +2,4 @@ mod layout; mod tabs; pub(super) use layout::*; -pub(self) use tabs::*; +use tabs::*; diff --git a/app/src/main.rs b/app/src/main.rs index 049ddd3f..77ae1bec 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -1,3 +1,5 @@ +#![allow(clippy::module_inception)] + mod app; mod context; mod executor; @@ -12,12 +14,12 @@ mod status; mod tasks; mod which; -pub(self) use app::*; -pub(self) use context::*; -pub(self) use executor::*; -pub(self) use logs::*; -pub(self) use root::*; -pub(self) use signals::*; +use app::*; +use context::*; +use executor::*; +use logs::*; +use root::*; +use signals::*; #[tokio::main] async fn main() -> anyhow::Result<()> { diff --git a/app/src/manager/folder.rs b/app/src/manager/folder.rs index ddc20bb6..1ca704f3 100644 --- a/app/src/manager/folder.rs +++ b/app/src/manager/folder.rs @@ -38,7 +38,7 @@ impl<'a> Folder<'a> { .iter() .find(|x| x.matches(&file.path, mimetype.get(&file.path).cloned(), file.meta.is_dir())) .map(|x| x.style.get()) - .unwrap_or_else(|| Style::new()) + .unwrap_or_else(Style::new) } } diff --git a/app/src/manager/layout.rs b/app/src/manager/layout.rs index 57e174ec..5d401da6 100644 --- a/app/src/manager/layout.rs +++ b/app/src/manager/layout.rs @@ -31,7 +31,7 @@ impl<'a> Widget for Layout<'a> { // Parent let block = Block::new().borders(Borders::RIGHT).padding(Padding::new(1, 0, 0, 0)); - if let Some(ref parent) = manager.parent() { + if let Some(parent) = manager.parent() { Folder::new(self.cx, parent).render(block.inner(chunks[0]), buf); } block.render(chunks[0], buf); diff --git a/app/src/manager/mod.rs b/app/src/manager/mod.rs index 3a32499f..8e077468 100644 --- a/app/src/manager/mod.rs +++ b/app/src/manager/mod.rs @@ -2,6 +2,6 @@ mod folder; mod layout; mod preview; -pub(self) use folder::*; +use folder::*; pub(super) use layout::*; -pub(self) use preview::*; +use preview::*; diff --git a/app/src/status/mod.rs b/app/src/status/mod.rs index a020bb96..35d6b256 100644 --- a/app/src/status/mod.rs +++ b/app/src/status/mod.rs @@ -4,6 +4,6 @@ mod progress; mod right; pub(super) use layout::*; -pub(self) use left::*; -pub(self) use progress::*; -pub(self) use right::*; +use left::*; +use progress::*; +use right::*; diff --git a/app/src/status/right.rs b/app/src/status/right.rs index ef415ba6..ba7906cb 100644 --- a/app/src/status/right.rs +++ b/app/src/status/right.rs @@ -34,7 +34,7 @@ impl<'a> Right<'a> { .collect() } - fn position<'b>(&self) -> Vec { + fn position(&self) -> Vec { // Colors let mode = self.cx.manager.active().mode(); let primary = mode.color(&THEME.status.primary); diff --git a/app/src/tasks/mod.rs b/app/src/tasks/mod.rs index 0bf8cc59..712c459e 100644 --- a/app/src/tasks/mod.rs +++ b/app/src/tasks/mod.rs @@ -1,5 +1,5 @@ mod clear; mod layout; -pub(self) use clear::*; +use clear::*; pub(super) use layout::*; diff --git a/app/src/which/mod.rs b/app/src/which/mod.rs index 2b637f9b..2ed246ae 100644 --- a/app/src/which/mod.rs +++ b/app/src/which/mod.rs @@ -2,4 +2,4 @@ mod layout; mod side; pub(super) use layout::*; -pub(self) use side::*; +use side::*; diff --git a/config/src/keymap/exec.rs b/config/src/keymap/exec.rs index e64abd28..64a79f36 100644 --- a/config/src/keymap/exec.rs +++ b/config/src/keymap/exec.rs @@ -13,11 +13,11 @@ impl From<&str> for Exec { fn from(value: &str) -> Self { let mut exec = Self::default(); for x in value.split_whitespace() { - if x.starts_with("--") { - let mut it = x[2..].splitn(2, '='); - let name = it.next().unwrap(); + if let Some(kv) = x.strip_prefix("--") { + let mut it = kv.splitn(2, '='); + let key = it.next().unwrap(); let value = it.next().unwrap_or(""); - exec.named.insert(name.to_string(), value.to_string()); + exec.named.insert(key.to_string(), value.to_string()); } else if exec.cmd.is_empty() { exec.cmd = x.to_string(); } else { diff --git a/config/src/keymap/key.rs b/config/src/keymap/key.rs index a5d71d07..94e96fa7 100644 --- a/config/src/keymap/key.rs +++ b/config/src/keymap/key.rs @@ -122,7 +122,6 @@ impl ToString for Key { } let code = match self.code { - KeyCode::Char(' ') => "Space", KeyCode::Backspace => "Backspace", KeyCode::Enter => "Enter", KeyCode::Left => "Left", @@ -150,7 +149,7 @@ impl ToString for Key { KeyCode::F(12) => "F12", KeyCode::Esc => "Esc", - KeyCode::Char(c) if c == ' ' => "Space", + KeyCode::Char(' ') => "Space", KeyCode::Char(c) => { s.push(if self.shift { c.to_ascii_uppercase() } else { c }); "" diff --git a/config/src/keymap/keymap.rs b/config/src/keymap/keymap.rs index 862d6b43..3c864368 100644 --- a/config/src/keymap/keymap.rs +++ b/config/src/keymap/keymap.rs @@ -54,9 +54,11 @@ impl<'de> Deserialize<'de> for Keymap { } } -impl Keymap { - pub fn new() -> Self { toml::from_str(&MERGED_KEYMAP).unwrap() } +impl Default for Keymap { + fn default() -> Self { toml::from_str(&MERGED_KEYMAP).unwrap() } +} +impl Keymap { #[inline] pub fn get(&self, layer: KeymapLayer) -> &Vec { match layer { diff --git a/config/src/lib.rs b/config/src/lib.rs index 1758c142..b2c0b3c0 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::module_inception)] + use once_cell::sync::Lazy; pub mod keymap; @@ -12,16 +14,16 @@ pub mod theme; pub(crate) use pattern::*; pub(crate) use preset::*; -static MERGED_KEYMAP: Lazy = Lazy::new(|| Preset::keymap()); -static MERGED_THEME: Lazy = Lazy::new(|| Preset::theme()); -static MERGED_YAZI: Lazy = Lazy::new(|| Preset::yazi()); +static MERGED_KEYMAP: Lazy = Lazy::new(Preset::keymap); +static MERGED_THEME: Lazy = Lazy::new(Preset::theme); +static MERGED_YAZI: Lazy = Lazy::new(Preset::yazi); -pub static KEYMAP: Lazy = Lazy::new(|| keymap::Keymap::new()); -pub static LOG: Lazy = Lazy::new(|| log::Log::new()); -pub static MANAGER: Lazy = Lazy::new(|| manager::Manager::new()); -pub static OPEN: Lazy = Lazy::new(|| open::Open::new()); -pub static PREVIEW: Lazy = Lazy::new(|| preview::Preview::new()); -pub static THEME: Lazy = Lazy::new(|| theme::Theme::new()); +pub static KEYMAP: Lazy = Lazy::new(Default::default); +pub static LOG: Lazy = Lazy::new(Default::default); +pub static MANAGER: Lazy = Lazy::new(Default::default); +pub static OPEN: Lazy = Lazy::new(Default::default); +pub static PREVIEW: Lazy = Lazy::new(Default::default); +pub static THEME: Lazy = Lazy::new(Default::default); pub fn init() { Lazy::force(&KEYMAP); diff --git a/config/src/log/log.rs b/config/src/log/log.rs index f112cf1a..e90b92cb 100644 --- a/config/src/log/log.rs +++ b/config/src/log/log.rs @@ -10,8 +10,8 @@ pub struct Log { pub root: PathBuf, } -impl Log { - pub fn new() -> Self { toml::from_str(&MERGED_YAZI).unwrap() } +impl Default for Log { + fn default() -> Self { toml::from_str(&MERGED_YAZI).unwrap() } } impl<'de> Deserialize<'de> for Log { diff --git a/config/src/manager/manager.rs b/config/src/manager/manager.rs index 49440da9..c270ab79 100644 --- a/config/src/manager/manager.rs +++ b/config/src/manager/manager.rs @@ -20,8 +20,8 @@ pub struct Manager { pub show_hidden: bool, } -impl Manager { - pub fn new() -> Self { +impl Default for Manager { + fn default() -> Self { #[derive(Deserialize)] struct Outer { manager: Manager, diff --git a/config/src/open/open.rs b/config/src/open/open.rs index 68b43d91..f5280cec 100644 --- a/config/src/open/open.rs +++ b/config/src/open/open.rs @@ -20,9 +20,11 @@ struct OpenRule { use_: String, } -impl Open { - pub fn new() -> Self { toml::from_str(&MERGED_YAZI).unwrap() } +impl Default for Open { + fn default() -> Self { toml::from_str(&MERGED_YAZI).unwrap() } +} +impl Open { pub fn openers(&self, path: P, mime: M) -> Option> where P: AsRef, @@ -39,11 +41,8 @@ impl Open { }) } - pub fn common_openers<'a>( - &self, - targets: &[(impl AsRef, impl AsRef)], - ) -> Vec<&Opener> { - let grouped = targets.into_iter().filter_map(|(p, m)| self.openers(p, m)).collect::>(); + pub fn common_openers(&self, targets: &[(impl AsRef, impl AsRef)]) -> Vec<&Opener> { + let grouped = targets.iter().filter_map(|(p, m)| self.openers(p, m)).collect::>(); let flat = grouped.iter().flatten().cloned().collect::>(); flat.into_iter().filter(|o| grouped.iter().all(|g| g.contains(o))).collect() } diff --git a/config/src/preview/adaptor.rs b/config/src/preview/adaptor.rs index 2f5580e7..24bc1916 100644 --- a/config/src/preview/adaptor.rs +++ b/config/src/preview/adaptor.rs @@ -28,12 +28,13 @@ impl Default for PreviewAdaptor { match env::var("TERM_PROGRAM").unwrap_or_default().as_str() { "iTerm.app" => return Self::Iterm2, "WezTerm" => return Self::Kitty, + "vscode" => return Self::Sixel, "Hyper" => return Self::Sixel, _ => {} } match env::var("XDG_SESSION_TYPE").unwrap_or_default().as_str() { - "x11" => return Self::X11, - "wayland" => return Self::Wayland, + "x11" => Self::X11, + "wayland" => Self::Wayland, _ => Self::Chafa, } } @@ -56,11 +57,6 @@ impl ToString for PreviewAdaptor { impl PreviewAdaptor { #[inline] pub fn needs_ueberzug(&self) -> bool { - match self { - PreviewAdaptor::Kitty => false, - PreviewAdaptor::Iterm2 => false, - PreviewAdaptor::Sixel => false, - _ => true, - } + !matches!(self, PreviewAdaptor::Kitty | PreviewAdaptor::Iterm2 | PreviewAdaptor::Sixel) } } diff --git a/config/src/preview/preview.rs b/config/src/preview/preview.rs index d5180bc2..80058a4d 100644 --- a/config/src/preview/preview.rs +++ b/config/src/preview/preview.rs @@ -13,8 +13,8 @@ pub struct Preview { pub max_height: u32, } -impl Preview { - pub fn new() -> Self { +impl Default for Preview { + fn default() -> Self { #[derive(Deserialize)] struct Outer { preview: Preview, diff --git a/config/src/theme/theme.rs b/config/src/theme/theme.rs index 8b8adf19..34adc49e 100644 --- a/config/src/theme/theme.rs +++ b/config/src/theme/theme.rs @@ -69,8 +69,8 @@ pub struct Theme { pub icons: Vec, } -impl Theme { - pub fn new() -> Self { +impl Default for Theme { + fn default() -> Self { let mut theme: Self = toml::from_str(&MERGED_THEME).unwrap(); theme.preview.syntect_theme = futures::executor::block_on(absolute_path(&theme.preview.syntect_theme)); diff --git a/core/src/external/file.rs b/core/src/external/file.rs index 5b2c2913..e52771ee 100644 --- a/core/src/external/file.rs +++ b/core/src/external/file.rs @@ -19,13 +19,13 @@ pub async fn file(files: &[impl AsRef]) -> Result) -> Result<()> { if !output.status.success() { bail!("failed to generate PDF thumbnail: {}", String::from_utf8_lossy(&output.stderr)); } - Ok(Image::precache_anyway(output.stdout.into(), dest).await?) + Image::precache_anyway(output.stdout.into(), dest).await } diff --git a/core/src/external/rg.rs b/core/src/external/rg.rs index 9705f9c3..c63aa322 100644 --- a/core/src/external/rg.rs +++ b/core/src/external/rg.rs @@ -13,7 +13,7 @@ pub struct RgOpt { pub fn rg(opt: RgOpt) -> Result>> { let mut child = Command::new("rg") .current_dir(&opt.cwd) - .args(&["--color=never", "--files-with-matches", "--smart-case"]) + .args(["--color=never", "--files-with-matches", "--smart-case"]) .arg(if opt.hidden { "--hidden" } else { "--no-hidden" }) .arg(&opt.subject) .kill_on_drop(true) diff --git a/core/src/external/unar.rs b/core/src/external/unar.rs index b893b982..77270ba6 100644 --- a/core/src/external/unar.rs +++ b/core/src/external/unar.rs @@ -5,8 +5,8 @@ use tokio::{io::{AsyncReadExt, BufReader}, process::Command}; pub async fn unar_head(path: &Path, target: &Path) -> Result> { let mut child = Command::new("unar") - .args(&[path, target]) - .args(&["-o", "-"]) + .args([path, target]) + .args(["-o", "-"]) .stdout(Stdio::piped()) .stderr(Stdio::null()) .kill_on_drop(true) diff --git a/core/src/external/zoxide.rs b/core/src/external/zoxide.rs index 5bcb0657..fbd57671 100644 --- a/core/src/external/zoxide.rs +++ b/core/src/external/zoxide.rs @@ -9,7 +9,7 @@ pub struct ZoxideOpt { pub fn zoxide(opt: ZoxideOpt) -> Result>> { let child = Command::new("zoxide") - .args(&["query", "-i", "--exclude"]) + .args(["query", "-i", "--exclude"]) .arg(opt.cwd) .kill_on_drop(true) .stdout(Stdio::piped()) diff --git a/core/src/input/input.rs b/core/src/input/input.rs index 9f25fc44..67b7f2c1 100644 --- a/core/src/input/input.rs +++ b/core/src/input/input.rs @@ -103,7 +103,7 @@ impl Input { let snap = self.snap(); let b = self.handle_op( if step <= 0 { - snap.cursor.saturating_sub(step.abs() as usize) + snap.cursor.saturating_sub(step.unsigned_abs()) } else { snap.count().min(snap.cursor + step as usize) }, @@ -333,11 +333,7 @@ impl Input { pub fn selected(&self) -> Option { let snap = self.snap(); - let start = if let Some(s) = snap.op.start() { - s - } else { - return None; - }; + let start = snap.op.start()?; let (start, end) = if start < snap.cursor { (start, snap.cursor) } else { (snap.cursor + 1, start + 1) }; diff --git a/core/src/input/snaps.rs b/core/src/input/snaps.rs index 3b882a29..0dc203df 100644 --- a/core/src/input/snaps.rs +++ b/core/src/input/snaps.rs @@ -52,7 +52,7 @@ impl InputSnaps { #[inline] pub(super) fn catch(&mut self) { - let value = mem::replace(&mut self.versions[self.idx].value, String::new()); + let value = mem::take(&mut self.versions[self.idx].value); self.versions[self.idx] = self.current.clone(); self.versions[self.idx].value = value; self.versions[self.idx].reset(); diff --git a/core/src/lib.rs b/core/src/lib.rs index c34ce75d..d2b49c8b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,3 +1,10 @@ +#![allow( + clippy::if_same_then_else, + clippy::len_without_is_empty, + clippy::module_inception, + clippy::option_map_unit_fn +)] + mod blocker; mod event; pub mod external; diff --git a/core/src/manager/manager.rs b/core/src/manager/manager.rs index 3b047f16..f2f0790a 100644 --- a/core/src/manager/manager.rs +++ b/core/src/manager/manager.rs @@ -17,9 +17,9 @@ pub struct Manager { } impl Manager { - pub fn new() -> Self { + pub fn make() -> Self { Self { - tabs: Tabs::new(), + tabs: Tabs::make(), yanked: Default::default(), watcher: Watcher::start(), diff --git a/core/src/manager/preview.rs b/core/src/manager/preview.rs index db303eb9..1d152180 100644 --- a/core/src/manager/preview.rs +++ b/core/src/manager/preview.rs @@ -45,7 +45,7 @@ impl Preview { } pub fn go(&mut self, path: &Path, mime: &str, show_image: bool) { - let kind = MimeKind::new(&mime); + let kind = MimeKind::new(mime); if !show_image && matches!(kind, MimeKind::Image | MimeKind::Video) { return; } else if self.same(path, mime) { @@ -99,7 +99,7 @@ impl Preview { } pub async fn folder(path: &Path) -> Result { - emit!(Files(match Files::read_dir(&path).await { + emit!(Files(match Files::read_dir(path).await { Ok(items) => FilesOp::Read(path.to_path_buf(), items), Err(_) => FilesOp::IOErr(path.to_path_buf()), })); diff --git a/core/src/manager/tab.rs b/core/src/manager/tab.rs index c7e1135e..719fb57d 100644 --- a/core/src/manager/tab.rs +++ b/core/src/manager/tab.rs @@ -23,7 +23,7 @@ impl Tab { Self { mode: Default::default(), current: Folder::new(path), - parent: path.parent().map(|p| Folder::new(p)), + parent: path.parent().map(Folder::new), search: None, @@ -54,7 +54,7 @@ impl Tab { let ok = if step > 0 { self.current.next(step as usize) } else { - self.current.prev(step.abs() as usize) + self.current.prev(step.unsigned_abs()) }; if !ok { return false; diff --git a/core/src/manager/tabs.rs b/core/src/manager/tabs.rs index d97c569f..bf4d2890 100644 --- a/core/src/manager/tabs.rs +++ b/core/src/manager/tabs.rs @@ -13,7 +13,7 @@ pub struct Tabs { } impl Tabs { - pub fn new() -> Self { + pub fn make() -> Self { let mut tabs = Self { idx: usize::MAX, items: vec![Tab::new(&MANAGER.cwd)] }; tabs.set_idx(0); tabs @@ -53,7 +53,7 @@ impl Tabs { pub fn close(&mut self, idx: usize) -> bool { let len = self.items.len(); - if len < 2 || idx as usize >= len { + if len < 2 || idx >= len { return false; } @@ -70,7 +70,7 @@ impl Tabs { if rel > 0 { (self.idx + rel as usize).min(self.items.len() - 1) } else { - self.idx.saturating_sub(rel.abs() as usize) + self.idx.saturating_sub(rel.unsigned_abs()) } } diff --git a/core/src/manager/watcher.rs b/core/src/manager/watcher.rs index 5f99843b..18e4b334 100644 --- a/core/src/manager/watcher.rs +++ b/core/src/manager/watcher.rs @@ -56,7 +56,7 @@ impl Watcher { tx.blocking_send(path).ok(); tx.blocking_send(parent).ok(); } - _ => return, + _ => (), } } }, @@ -111,7 +111,7 @@ impl Watcher { self.watcher.unwatch(p).ok(); } for p in to_watch.clone().difference(&keys) { - if self.watcher.watch(&p, RecursiveMode::NonRecursive).is_err() { + if self.watcher.watch(p, RecursiveMode::NonRecursive).is_err() { to_watch.remove(p); } } diff --git a/core/src/tasks/running.rs b/core/src/tasks/running.rs index 5b068bfd..1f38f2b0 100644 --- a/core/src/tasks/running.rs +++ b/core/src/tasks/running.rs @@ -27,9 +27,7 @@ impl Running { pub(super) fn get_mut(&mut self, id: usize) -> Option<&mut Task> { self.all.get_mut(&id) } #[inline] - pub(super) fn get_id(&self, idx: usize) -> Option { - self.values().skip(idx).next().map(|t| t.id) - } + pub(super) fn get_id(&self, idx: usize) -> Option { self.values().nth(idx).map(|t| t.id) } #[inline] pub(super) fn len(&self) -> usize { self.all.len() } diff --git a/core/src/tasks/task.rs b/core/src/tasks/task.rs index fdee3349..c6010475 100644 --- a/core/src/tasks/task.rs +++ b/core/src/tasks/task.rs @@ -46,16 +46,16 @@ impl Task { } } -impl Into for &Task { - fn into(self) -> TaskSummary { +impl From<&Task> for TaskSummary { + fn from(task: &Task) -> Self { TaskSummary { - name: self.name.clone(), + name: task.name.clone(), - found: self.found, - processed: self.processed, + found: task.found, + processed: task.processed, - todo: self.todo, - done: self.done, + todo: task.todo, + done: task.done, } } } diff --git a/core/src/tasks/tasks.rs b/core/src/tasks/tasks.rs index c3e31ae3..8d0f952f 100644 --- a/core/src/tasks/tasks.rs +++ b/core/src/tasks/tasks.rs @@ -38,6 +38,7 @@ impl Tasks { true } + #[allow(clippy::should_implement_trait)] pub fn next(&mut self) -> bool { let limit = Self::limit().min(self.len()); @@ -132,7 +133,7 @@ impl Tasks { let mut openers = BTreeMap::new(); for (path, mime) in targets { if let Some(opener) = OPEN.openers(path, mime).and_then(|o| o.first().cloned()) { - openers.entry(opener).or_insert_with(|| vec![]).push(path.as_ref()); + openers.entry(opener).or_insert_with(Vec::new).push(path.as_ref()); } } for (opener, args) in openers { @@ -143,13 +144,13 @@ impl Tasks { pub fn file_open_with(&self, opener: &Opener, args: &[impl AsRef]) -> bool { if opener.spread { - self.scheduler.process_open(&opener, args); + self.scheduler.process_open(opener, args); return false; } for target in args { - self.scheduler.process_open(&opener, &[target]); + self.scheduler.process_open(opener, &[target]); } - return false; + false } pub fn file_cut(&self, src: &HashSet, dest: PathBuf, force: bool) -> bool { @@ -238,7 +239,7 @@ impl Tasks { pub fn precache_image(&self, mimetype: &BTreeMap) -> bool { let targets = mimetype - .into_iter() + .iter() .filter(|(_, m)| MimeKind::new(m) == MimeKind::Image) .map(|(p, _)| p.clone()) .collect::>(); @@ -251,7 +252,7 @@ impl Tasks { pub fn precache_video(&self, mimetype: &BTreeMap) -> bool { let targets = mimetype - .into_iter() + .iter() .filter(|(_, m)| MimeKind::new(m) == MimeKind::Video) .map(|(p, _)| p.clone()) .collect::>(); @@ -264,7 +265,7 @@ impl Tasks { pub fn precache_pdf(&self, mimetype: &BTreeMap) -> bool { let targets = mimetype - .into_iter() + .iter() .filter(|(_, m)| MimeKind::new(m) == MimeKind::PDF) .map(|(p, _)| p.clone()) .collect::>(); diff --git a/core/src/tasks/workers/precache.rs b/core/src/tasks/workers/precache.rs index 1b5097f7..30951710 100644 --- a/core/src/tasks/workers/precache.rs +++ b/core/src/tasks/workers/precache.rs @@ -21,7 +21,7 @@ pub(crate) struct Precache { pub(crate) enum PrecacheOp { Image(PrecacheOpImage), Video(PrecacheOpVideo), - PDF(PrecacheOpPDF), + Pdf(PrecacheOpPDF), } #[derive(Debug)] @@ -66,7 +66,7 @@ impl Precache { Ok(match self.rx.recv().await? { PrecacheOp::Image(t) => (t.id, PrecacheOp::Image(t)), PrecacheOp::Video(t) => (t.id, PrecacheOp::Video(t)), - PrecacheOp::PDF(t) => (t.id, PrecacheOp::PDF(t)), + PrecacheOp::Pdf(t) => (t.id, PrecacheOp::Pdf(t)), }) } @@ -91,7 +91,7 @@ impl Precache { external::ffmpegthumbnailer(&task.target, &cache).await.ok(); self.sch.send(TaskOp::Adv(task.id, 1, 0))?; } - PrecacheOp::PDF(task) => { + PrecacheOp::Pdf(task) => { let cache = Image::cache(&task.target); if fs::metadata(&cache).await.is_ok() { return Ok(self.sch.send(TaskOp::Adv(task.id, 1, 0))?); @@ -159,7 +159,7 @@ impl Precache { pub(crate) fn pdf(&self, id: usize, targets: Vec) -> Result<()> { for target in targets { self.sch.send(TaskOp::New(id, 0))?; - self.tx.send_blocking(PrecacheOp::PDF(PrecacheOpPDF { id, target }))?; + self.tx.send_blocking(PrecacheOp::Pdf(PrecacheOpPDF { id, target }))?; } self.done(id) } diff --git a/core/src/which/which.rs b/core/src/which/which.rs index f33e28ea..758bb101 100644 --- a/core/src/which/which.rs +++ b/core/src/which/which.rs @@ -22,18 +22,14 @@ impl Which { pub fn show(&mut self, key: &Key, layer: KeymapLayer) -> bool { self.layer = layer; self.times = 1; - self.cands = KEYMAP - .get(layer) - .into_iter() - .filter(|s| s.on.len() > 1 && s.on[0] == *key) - .cloned() - .collect(); + self.cands = + KEYMAP.get(layer).iter().filter(|s| s.on.len() > 1 && s.on[0] == *key).cloned().collect(); self.switch(true); true } pub fn press(&mut self, key: Key) -> bool { - self.cands = mem::replace(&mut self.cands, Vec::new()) + self.cands = mem::take(&mut self.cands) .into_iter() .filter(|s| s.on.len() > self.times && s.on[self.times] == key) .collect(); @@ -49,7 +45,7 @@ impl Which { } self.times += 1; - return true; + true } #[inline] diff --git a/cspell.json b/cspell.json index 120b2a9b..fd74b8cd 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"version":"0.2","flagWords":[],"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF"]} +{"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt"],"language":"en","version":"0.2","flagWords":[]} diff --git a/shared/src/fs.rs b/shared/src/fs.rs index 336d771c..75f9ce24 100644 --- a/shared/src/fs.rs +++ b/shared/src/fs.rs @@ -98,6 +98,7 @@ pub fn copy_with_progress(from: &Path, to: &Path) -> mpsc::Receiver String { use libc::{S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFSOCK, S_IRGRP, S_IROTH, S_IRUSR, S_ISGID, S_ISUID, S_ISVTX, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR}; diff --git a/shared/src/mime.rs b/shared/src/mime.rs index a59df274..04831d6e 100644 --- a/shared/src/mime.rs +++ b/shared/src/mime.rs @@ -28,19 +28,8 @@ impl MimeKind { return false; } - let b = match parts[0] { - "application" => true, - "audio" => true, - "example" => true, - "font" => true, - "image" => true, - "message" => true, - "model" => true, - "multipart" => true, - "text" => true, - "video" => true, - _ => false, - }; + #[rustfmt::skip] + let b = matches!(parts[0], "application" | "audio" | "example" | "font" | "image" | "message" | "model" | "multipart" | "text" | "video"); b && !parts[1].is_empty() } diff --git a/shared/src/throttle.rs b/shared/src/throttle.rs index 9404655b..248eaa69 100644 --- a/shared/src/throttle.rs +++ b/shared/src/throttle.rs @@ -47,7 +47,7 @@ impl Throttle { where F: FnOnce(Vec), { - let mut buf = mem::replace(&mut *self.buf.lock(), Vec::new()); + let mut buf = mem::take(&mut *self.buf.lock()); buf.push(data); f(buf) }