Skip to main content

Extract extension as a separate variable

ID
a0582b8
date
2024-09-04 06:40:52+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
2c66178
message
Extract `extension` as a separate variable
changed files
1 file, 7 additions, 2 deletions

Changed files

src/get_image_colors.rs (5513) → src/get_image_colors.rs (5613)

diff --git a/src/get_image_colors.rs b/src/get_image_colors.rs
index df990fc..83cc28a 100644
--- a/src/get_image_colors.rs
+++ b/src/get_image_colors.rs
@@ -18,8 +18,13 @@ use palette::cast::from_component_slice;
 use palette::{IntoColor, Lab, Srgba};
 
 pub fn get_image_colors(path: &PathBuf) -> Vec<Lab> {
-    let image_bytes = match path.extension().and_then(OsStr::to_str) {
-        Some(ext) if ext.to_lowercase() == "gif" => get_bytes_for_gif(&path),
+    let extension = match path.extension().and_then(OsStr::to_str) {
+        Some(ext) => Some(ext.to_lowercase()),
+        None => None,
+    };
+
+    let image_bytes = match extension {
+        Some(ext) if ext == "gif" => get_bytes_for_gif(&path),
         _ => get_bytes_for_non_gif(&path),
     };