[niepce] npc-engine: Implement FileType::Into<&str>



commit dec59052a3550402cd36f116623d6e8bd3ba9288
Author: Hubert Figuière <hub figuiere net>
Date:   Tue Dec 29 11:50:23 2020 -0500

    npc-engine: Implement FileType::Into<&str>

 crates/npc-engine/src/db/libfile.rs     | 18 ++++++++++++++++++
 crates/npc-engine/src/db/libmetadata.rs |  9 +--------
 2 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/crates/npc-engine/src/db/libfile.rs b/crates/npc-engine/src/db/libfile.rs
index c8c0efc..7cede33 100644
--- a/crates/npc-engine/src/db/libfile.rs
+++ b/crates/npc-engine/src/db/libfile.rs
@@ -33,11 +33,17 @@ use npc_fwk::base::PropertyIndex;
 
 #[repr(i32)]
 #[derive(Debug, Copy, Clone, PartialEq)]
+/// A general type of the LibFile.
 pub enum FileType {
+    /// Don't know
     Unknown = 0,
+    /// Camera Raw
     Raw = 1,
+    /// Bundle of RAW + processed. Don't assume JPEG.
     RawJpeg = 2,
+    /// Processed Image
     Image = 3,
+    /// Video
     Video = 4,
 }
 
@@ -76,6 +82,18 @@ impl From<i32> for FileType {
     }
 }
 
+impl Into<&'static str> for FileType {
+    fn into(self) -> &'static str {
+        match self {
+            FileType::Unknown => "Unknown",
+            FileType::Raw => "RAW",
+            FileType::RawJpeg => "RAW + JPEG",
+            FileType::Image => "Image",
+            FileType::Video => "Video",
+        }
+    }
+}
+
 impl Into<i32> for FileType {
     fn into(self) -> i32 {
         match self {
diff --git a/crates/npc-engine/src/db/libmetadata.rs b/crates/npc-engine/src/db/libmetadata.rs
index 0911bc5..efc4d3a 100644
--- a/crates/npc-engine/src/db/libmetadata.rs
+++ b/crates/npc-engine/src/db/libmetadata.rs
@@ -237,14 +237,7 @@ impl LibMetadata {
                     props.set_value(*prop_id, PropertyValue::String(self.name.clone()));
                 }
                 eng::NpFileTypeProp => {
-                    // XXX this to string convert should be elsewhere
-                    let file_type = match self.file_type {
-                        FileType::Unknown => "Unknown",
-                        FileType::Raw => "RAW",
-                        FileType::RawJpeg => "RAW + JPEG",
-                        FileType::Image => "Image",
-                        FileType::Video => "Video",
-                    };
+                    let file_type: &str = self.file_type.into();
                     props.set_value(*prop_id, PropertyValue::String(String::from(file_type)));
                 }
                 eng::NpFileSizeProp => {}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]