aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2018-12-01 11:53:36 -0800
committerOskari Timperi <oskari.timperi@iki.fi>2018-12-01 11:53:36 -0800
commitf428a84b1668326bcd57703fa7dfb1cd1520af84 (patch)
treeda115e77edf535be7502db84fce3a5880657454b
parent2f8429643fd726d761851dd4348e428708ada589 (diff)
downloadplag-f428a84b1668326bcd57703fa7dfb1cd1520af84.tar.gz
plag-f428a84b1668326bcd57703fa7dfb1cd1520af84.zip
Refactor properties a bit
-rw-r--r--src/main.rs14
1 files 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<Feature> {
let file = std::fs::File::open(filename)?;
@@ -139,9 +147,11 @@ fn get_feature(filename: &Path, properties: &[Property]) -> Result<Feature> {
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 {