From f428a84b1668326bcd57703fa7dfb1cd1520af84 Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Sat, 1 Dec 2018 11:53:36 -0800 Subject: Refactor properties a bit --- src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 96ad078..d031496 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,6 +127,14 @@ enum Property { Filename, } +impl std::fmt::Display for Property { + fn fmt(&self, w: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Property::Filename => write!(w, "filename"), + } + } +} + fn get_feature(filename: &Path, properties: &[Property]) -> Result { let file = std::fs::File::open(filename)?; @@ -139,9 +147,11 @@ fn get_feature(filename: &Path, properties: &[Property]) -> Result { let mut props = Map::new(); for prop in properties { - match prop { - Property::Filename => props.insert("filename".to_string(), to_value(filename.file_name().unwrap().to_string_lossy()).unwrap()), + let key = prop.to_string(); + let value = match prop { + Property::Filename => to_value(filename.file_name().unwrap().to_string_lossy()) }; + props.insert(key, value.unwrap()); } Ok(Feature { -- cgit v1.2.3