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
use std::collections::BTreeMap;
use crate::imp::structs::my_json::Value;
#[derive(Debug)]
pub struct JsonFileImpl{
pub filename_without_ext : String,
pub json : String,
}
impl JsonFile for &JsonFileImpl{
fn filename_without_ext(&self) -> &str {
&self.filename_without_ext
}
fn json(&self) -> &str {
&self.json
}
}
pub trait JsonFile{
fn filename_without_ext(&self) -> &str;
fn json(&self) -> &str;
}
impl JsonFile for (&str, &str){
fn filename_without_ext(&self) -> &str {
self.0
}
fn json(&self) -> &str {
self.1
}
}
#[derive(Debug)]
pub struct JsonDir(pub BTreeMap<String, Value>);
impl JsonDir{
pub fn to_string(&self) -> String{
let mut result = String::new();
let map = &self.0;
for (name, value) in map{
result.push_str(&format!("{} : {}\n",name, value.to_string_pretty()));
}
return result;
}
}