conf_parser/processer/
file.rs1use std::collections::HashMap;
2
3#[derive(Default, Debug, Clone)]
6pub struct FileConf {
7 pub sections: HashMap<String, Section>,
8}
9
10impl FileConf {
11 pub fn new() -> Self {
12 FileConf {
13 sections: HashMap::new(),
14 }
15 }
16}
17
18#[derive(Debug, Clone)]
19pub struct Section {
20 properties: HashMap<String, String>,
21}
22
23impl Default for Section {
24 fn default() -> Self {
25 Self::new()
26 }
27}
28
29impl Section {
30 pub fn new() -> Self {
31 Section {
32 properties: HashMap::new(),
33 }
34 }
35 pub fn get_properties(self) -> HashMap<String, String> {
36 self.properties
37 }
38 pub fn get_property(&self, name: &str) -> String {
39 match self.properties.get(name) {
40 Some(item) => item.to_string(),
41 None => "".to_string(),
42 }
43 }
44 pub fn set_property(&mut self, name: &str, value: &str) {
45 if self.properties.contains_key("name") {
46 self.properties.remove("name");
47 }
48 self.properties.insert(name.to_owned(), value.to_owned());
49 }
50}