1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
use serde_derive::Deserialize;
use std::collections::HashMap;
use super::{parse_to_config_file, ConfigStructure, Flattenable};
use crate::PREVIEW_FILE;
#[derive(Debug, Deserialize)]
pub struct JoshutoPreviewEntry {
pub program: String,
pub args: Option<Vec<String>>,
}
#[derive(Debug, Deserialize)]
struct JoshutoRawPreview {
pub extension: Option<HashMap<String, JoshutoPreviewEntry>>,
pub mimetype: Option<HashMap<String, JoshutoPreviewEntry>>,
}
impl std::default::Default for JoshutoRawPreview {
fn default() -> Self {
JoshutoRawPreview {
extension: None,
mimetype: None,
}
}
}
impl Flattenable<JoshutoPreview> for JoshutoRawPreview {
fn flatten(self) -> JoshutoPreview {
let extension = self.extension.unwrap_or_default();
let mimetype = self.mimetype.unwrap_or_default();
JoshutoPreview {
extension,
mimetype,
}
}
}
#[derive(Debug)]
pub struct JoshutoPreview {
pub extension: HashMap<String, JoshutoPreviewEntry>,
pub mimetype: HashMap<String, JoshutoPreviewEntry>,
}
impl ConfigStructure for JoshutoPreview {
fn get_config() -> Self {
parse_to_config_file::<JoshutoRawPreview, JoshutoPreview>(PREVIEW_FILE)
.unwrap_or_else(JoshutoPreview::default)
}
}
impl std::default::Default for JoshutoPreview {
fn default() -> Self {
JoshutoPreview {
extension: HashMap::new(),
mimetype: HashMap::new(),
}
}
}
|