summaryrefslogtreecommitdiffstats
path: root/src/config/mimetype/registry.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/mimetype/registry.rs')
-rw-r--r--src/config/mimetype/registry.rs57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/config/mimetype/registry.rs b/src/config/mimetype/registry.rs
index f3736eb..26ba824 100644
--- a/src/config/mimetype/registry.rs
+++ b/src/config/mimetype/registry.rs
@@ -1,41 +1,20 @@
use serde_derive::Deserialize;
use std::collections::HashMap;
+use crate::config::{parse_to_config_file, TomlConfigFile};
+
use super::{AppList, AppMimetypeEntry};
-use crate::config::{parse_to_config_file, ConfigStructure, Flattenable};
pub type MimetypeRegistry = HashMap<String, AppList>;
#[derive(Debug, Deserialize)]
-pub struct RawAppMimetypeRegistry {
+pub struct AppMimetypeRegistryCrude {
#[serde(default, rename = "class")]
pub _class: HashMap<String, Vec<AppMimetypeEntry>>,
#[serde(default, rename = "extension")]
pub _extension: MimetypeRegistry,
}
-impl Flattenable<AppMimetypeRegistry> for RawAppMimetypeRegistry {
- fn flatten(self) -> AppMimetypeRegistry {
- let mut registry = MimetypeRegistry::new();
-
- for (ext, app_list) in self._extension {
- let class = app_list.parent();
- let mut combined_app_list: Vec<AppMimetypeEntry> = self
- ._class
- .get(class)
- .map(|v| (*v).clone())
- .unwrap_or_default();
- combined_app_list.extend_from_slice(app_list.app_list());
- let combined_app_list = AppList::new(class.to_string(), combined_app_list);
- registry.insert(ext, combined_app_list);
- }
-
- AppMimetypeRegistry {
- _extension: registry,
- }
- }
-}
-
#[derive(Debug)]
pub struct AppMimetypeRegistry {
// pub _class: HashMap<String, Vec<AppMimetypeEntry>>,
@@ -53,10 +32,25 @@ impl AppMimetypeRegistry {
}
}
-impl ConfigStructure for AppMimetypeRegistry {
- fn get_config(file_name: &str) -> Self {
- parse_to_config_file::<RawAppMimetypeRegistry, AppMimetypeRegistry>(file_name)
- .unwrap_or_else(Self::default)
+impl From<AppMimetypeRegistryCrude> for AppMimetypeRegistry {
+ fn from(crude: AppMimetypeRegistryCrude) -> Self {
+ let mut registry = MimetypeRegistry::new();
+
+ for (ext, app_list) in crude._extension {
+ let class = app_list.parent();
+ let mut combined_app_list: Vec<AppMimetypeEntry> = crude
+ ._class
+ .get(class)
+ .map(|v| (*v).clone())
+ .unwrap_or_default();
+ combined_app_list.extend_from_slice(app_list.app_list());
+ let combined_app_list = AppList::new(class.to_string(), combined_app_list);
+ registry.insert(ext, combined_app_list);
+ }
+
+ Self {
+ _extension: registry,
+ }
}
}
@@ -67,3 +61,10 @@ impl std::default::Default for AppMimetypeRegistry {
}
}
}
+
+impl TomlConfigFile for AppMimetypeRegistry {
+ fn get_config(file_name: &str) -> Self {
+ parse_to_config_file::<AppMimetypeRegistryCrude, AppMimetypeRegistry>(file_name)
+ .unwrap_or_else(Self::default)
+ }
+}