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
use std::collections::BTreeMap;
use toml::{self, to_string, from_str};

#[derive(Serialize, Deserialize)]
pub struct PackageMeta {
    pub name: String,
    pub version: String,
    pub target: String,
    pub depends: Vec<String>,
}

impl PackageMeta {
    pub fn new(name: &str, version: &str, target: &str, depends: Vec<String>) -> Self {
        PackageMeta {
            name: name.to_string(),
            version: version.to_string(),
            target: target.to_string(),
            depends: depends,
        }
    }

    pub fn from_toml(text: &str) -> Result<Self, toml::de::Error> {
       from_str(text)
    }

    pub fn to_toml(&self) -> String {
        // to_string *should* be safe to unwrap for this struct
        to_string(self).unwrap()
    }
}

#[derive(Serialize, Deserialize)]
pub struct PackageMetaList {
    pub packages: BTreeMap<String, String>,
}

impl PackageMetaList {
    pub fn new() -> Self {
        PackageMetaList {
            packages: BTreeMap::new()
        }
    }

    pub fn from_toml(text: &str) -> Result<Self, toml::de::Error> {
       from_str(text)
    }

    pub fn to_toml(&self) -> String {
        // to_string *should* be safe to unwrap for this struct
        to_string(self).unwrap()
    }
}