From ac23e536149e69f9ac5fc3f3307a0d698cbc7bb3 Mon Sep 17 00:00:00 2001 From: Nick Pegg Date: Tue, 6 May 2025 21:21:07 -0700 Subject: [PATCH] clippy pass --- src/generate.rs | 6 +++--- src/generate/album_dir.rs | 21 ++++++++++----------- src/main.rs | 8 ++++---- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/generate.rs b/src/generate.rs index 0fa70cb..3e584e2 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -71,7 +71,7 @@ impl TryFrom<&AlbumDir> for AlbumContext { log::debug!("Crumbs for {}: {breadcrumbs:?}", album.path.display()); // The first breadcrumb path is the relative path to the root album - let root_path = if breadcrumbs.len() > 0 { + let root_path = if !breadcrumbs.is_empty() { breadcrumbs[0].path.clone() } else { PathBuf::new() @@ -86,7 +86,7 @@ impl TryFrom<&AlbumDir> for AlbumContext { let children: Vec = album .children .iter() - .map(|a| AlbumContext::try_from(a)) + .map(AlbumContext::try_from) .collect::>>()?; let images: Vec = album.images.clone(); @@ -212,7 +212,7 @@ fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> { )?; for child in album.children.iter() { - dir_queue.push_back(&child); + dir_queue.push_back(child); } for (pos, img) in album.images.iter().enumerate() { diff --git a/src/generate/album_dir.rs b/src/generate/album_dir.rs index 9d64322..1c118bf 100644 --- a/src/generate/album_dir.rs +++ b/src/generate/album_dir.rs @@ -48,7 +48,7 @@ impl AlbumDir { } else { if filename.to_string_lossy().starts_with("cover") { cover = Some(Image::new( - entry_path.strip_prefix(&root)?.to_path_buf(), + entry_path.strip_prefix(root)?.to_path_buf(), String::new(), )?); } @@ -60,16 +60,15 @@ impl AlbumDir { // Read in any associated description file if entry_path.with_extension("txt").exists() { - description = - fs::read_to_string(&entry_path.with_extension("txt"))?; + description = fs::read_to_string(entry_path.with_extension("txt"))?; } else if entry_path.with_extension("md").exists() { - let _contents = fs::read(&entry_path.with_extension("md"))?; + let _contents = fs::read(entry_path.with_extension("md"))?; // TODO: render markdown todo!(); } images.push(Image::new( - entry_path.strip_prefix(&root)?.to_path_buf(), + entry_path.strip_prefix(root)?.to_path_buf(), description, )?); } @@ -85,12 +84,12 @@ impl AlbumDir { continue; } - children.push(AlbumDir::from_path(&entry_path, &root)?); + children.push(AlbumDir::from_path(&entry_path, root)?); } } } - if cover.is_none() && images.len() > 0 { + if cover.is_none() && !images.is_empty() { cover = Some(images[0].clone()); } @@ -201,7 +200,7 @@ impl Image { /// Returns the filename for a given slide type. For example if ext = "thumb" and the current /// filename is "blah.jpg" this will return "blah.thumb.jpg". If keep_ext if false, it would /// return "blah.thumb" - fn slide_filename(path: &PathBuf, ext: &str, keep_ext: bool) -> anyhow::Result { + fn slide_filename(path: &Path, ext: &str, keep_ext: bool) -> anyhow::Result { let mut new_ext: OsString = ext.into(); if keep_ext { if let Some(e) = path.extension() { @@ -228,11 +227,11 @@ impl Image { } /// Returns the path to the file in the slides dir given the path to the original image - fn slide_path(path: &PathBuf, file_name: &str) -> PathBuf { - let mut new_path = path.clone(); + fn slide_path(path: &Path, file_name: &str) -> PathBuf { + let mut new_path = path.to_path_buf(); new_path.pop(); new_path.push("slides"); - new_path.push(&file_name); + new_path.push(file_name); new_path } } diff --git a/src/main.rs b/src/main.rs index 454e48c..2ca6d06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ fn main() -> anyhow::Result<()> { make_skeleton(album_path)?; println!("Album created in {}", album_path.display()); } - Commands::Generate { quick } => { + Commands::Generate {} => { let path = generate(&album_path.to_path_buf())?; println!("Album site generated in {}", path.display()); } @@ -39,8 +39,8 @@ enum Commands { Init {}, /// Generates a photo album Generate { - /// Don't re-generate things that already exist (thumbnails, etc.) - #[arg(long)] - quick: bool, + // /// Don't re-generate things that already exist (thumbnails, etc.) + // #[arg(long)] + // _quick: bool, }, }