tikz-gallery-generator

Custum build of stapix for tikz.pablopie.xyz

Commit
1460d5928ca4b3340f70058e67e8de5d140f8e54
Parent
e3ce3993efa127e60197031b60a3455202502336
Author
Pablo <pablo-pie@riseup.net>
Date

Renamed a function

Replaced the thumb_path function with a Into implementation

Diffstats

1 files changed, 24 insertions, 22 deletions

Status Name Changes Insertions Deletions
Modified src/main.rs 2 files changed 24 22
diff --git a/src/main.rs b/src/main.rs
@@ -133,7 +133,7 @@ fn render_gallery(
 
   let mut render_pool_count = 0;
   for pic in &pics {
-    let thumb_path = thumb_path(pic);
+    let thumb_path: PathBuf = ThumbPath(pic).into();
     let thumb_meta = fs::metadata(&thumb_path);
 
     if !full_build {
@@ -503,27 +503,6 @@ fn render_thumbnail(pic: GalleryEntry, thumb_path: &Path) -> Result<(), ()> {
   Ok(())
 }
 
-// TODO: rename this?
-/// Helper to get the correct thumbnail path for a given entry
-fn thumb_path(pic: &GalleryEntry) -> PathBuf {
-  let mut result = PathBuf::from(TARGET_PATH);
-  result.push(THUMBS_PATH);
-
-  match pic.file_format {
-    FileFormat::TeX => {
-      result.push(pic.file_name.clone() + ".svg");
-    }
-    FileFormat::Svg => {
-      result.push(pic.file_name.clone());
-    }
-    FileFormat::Jpeg | FileFormat::Png => {
-      result.push(pic.file_name.clone() + ".webp");
-    }
-  }
-
-  result
-}
-
 fn create_file(path: &Path) -> io::Result<File> {
   File::create(path)
     .map_err(|e| { errorln!("Could not open file {path:?}: {e}"); e })
@@ -549,6 +528,29 @@ impl Display for ThumbPath<'_> {
   }
 }
 
+impl From<ThumbPath<'_>> for PathBuf {
+  fn from(thumb_path: ThumbPath<'_>) -> Self {
+    let pic = thumb_path.0;
+
+    let mut result = PathBuf::from(TARGET_PATH);
+    result.push(THUMBS_PATH);
+
+    match pic.file_format {
+      FileFormat::TeX => {
+        result.push(pic.file_name.clone() + ".svg");
+      }
+      FileFormat::Svg => {
+        result.push(&pic.file_name);
+      }
+      FileFormat::Jpeg | FileFormat::Png => {
+        result.push(pic.file_name.clone() + ".webp");
+      }
+    }
+
+    result
+  }
+}
+
 impl Display for Escaped<'_> {
   fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
     for c in self.0.chars() {