summaryrefslogtreecommitdiffstats
path: root/src/config/mimetype/list.rs
blob: 67373e9c83dc16647e451d4924210bffe185cc60 (plain)
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
61
62
63
64
65
66
use serde_derive::Deserialize;
use std::collections::HashMap;

use super::ProgramEntry;

#[derive(Clone, Debug, Deserialize)]
pub struct ExtensionAppListRaw {
    #[serde(default, rename = "inherit")]
    pub inherit_class: String,
    #[serde(default)]
    pub app_list: Vec<ProgramEntry>,
}

impl ExtensionAppListRaw {
    pub fn parent(&self) -> &str {
        self.inherit_class.as_str()
    }

    pub fn app_list(&self) -> &[ProgramEntry] {
        self.app_list.as_slice()
    }
}

pub type ExtensionAppList = Vec<ProgramEntry>;

#[derive(Clone, Debug, Deserialize)]
pub struct MimetypeAppListRaw {
    #[serde(default, rename = "inherit")]
    pub inherit_class: String,
    #[serde(default)]
    pub app_list: Vec<ProgramEntry>,
    #[serde(default)]
    pub subtype: Option<HashMap<String, ExtensionAppListRaw>>,
}

impl MimetypeAppListRaw {
    pub fn parent(&self) -> &str {
        self.inherit_class.as_str()
    }

    pub fn app_list(&self) -> &[ProgramEntry] {
        self.app_list.as_slice()
    }
}

#[derive(Clone, Debug)]
pub struct MimetypeAppList {
    _app_list: Vec<ProgramEntry>,
    _subtypes: HashMap<String, ExtensionAppList>,
}

impl MimetypeAppList {
    pub fn new(_app_list: Vec<ProgramEntry>, _subtypes: HashMap<String, ExtensionAppList>) -> Self {
        Self {
            _app_list,
            _subtypes,
        }
    }
    pub fn app_list(&self) -> &[ProgramEntry] {
        self._app_list.as_slice()
    }

    pub fn subtypes(&self) -> &HashMap<String, ExtensionAppList> {
        &self._subtypes
    }
}