pkgutils/
packagemeta.rs

1use serde_derive::{Deserialize, Serialize};
2use std::collections::BTreeMap;
3use toml::{self, from_str, to_string};
4
5#[derive(Serialize, Deserialize)]
6pub struct PackageMeta {
7    pub name: String,
8    pub version: String,
9    pub target: String,
10    pub depends: Vec<String>,
11}
12
13impl PackageMeta {
14    pub fn new(name: &str, version: &str, target: &str, depends: Vec<String>) -> Self {
15        PackageMeta {
16            name: name.to_string(),
17            version: version.to_string(),
18            target: target.to_string(),
19            depends: depends,
20        }
21    }
22
23    pub fn from_toml(text: &str) -> Result<Self, toml::de::Error> {
24        from_str(text)
25    }
26
27    pub fn to_toml(&self) -> String {
28        // to_string *should* be safe to unwrap for this struct
29        to_string(self).unwrap()
30    }
31}
32
33#[derive(Serialize, Deserialize)]
34pub struct PackageMetaList {
35    pub packages: BTreeMap<String, String>,
36}
37
38impl PackageMetaList {
39    pub fn new() -> Self {
40        PackageMetaList {
41            packages: BTreeMap::new(),
42        }
43    }
44
45    pub fn from_toml(text: &str) -> Result<Self, toml::de::Error> {
46        from_str(text)
47    }
48
49    pub fn to_toml(&self) -> String {
50        // to_string *should* be safe to unwrap for this struct
51        to_string(self).unwrap()
52    }
53}