docchi_core/imp/structs/
json_file.rs

1use std::collections::BTreeMap;
2use crate::imp::structs::my_json::Value;
3
4
5#[derive(Debug)]
6pub struct JsonFileImpl{
7    pub filename_without_ext : String,
8    pub json : String,
9}
10
11impl JsonFile for &JsonFileImpl{
12    fn filename_without_ext(&self) -> &str {
13        &self.filename_without_ext
14    }
15
16    fn json(&self) -> &str {
17        &self.json
18    }
19}
20
21pub trait JsonFile{
22    fn filename_without_ext(&self) -> &str;
23    fn json(&self) -> &str;
24}
25
26/// (filename_without_ext, json)
27impl JsonFile for (&str, &str){
28    fn filename_without_ext(&self) -> &str {
29        self.0
30    }
31
32    fn json(&self) -> &str {
33        self.1
34    }
35}
36
37#[derive(Debug)]
38pub struct JsonDir(pub BTreeMap<String, Value>);
39
40impl JsonDir{
41    pub fn to_string(&self) -> String{
42        let mut result = String::new();
43        let map = &self.0;
44        for (name, value) in map{
45
46            result.push_str(&format!("{} : {}\n",name, value.to_string_pretty()));
47        }
48        return result;
49    }
50}