2018-01-27 03:27:41 +00:00
|
|
|
/// config.rs
|
|
|
|
///
|
|
|
|
/// Contains Config structures, as well as means of serialising them.
|
|
|
|
|
|
|
|
use toml;
|
|
|
|
use toml::de::Error as TomlError;
|
|
|
|
|
|
|
|
use serde_json::{self, Error as SerdeError};
|
|
|
|
|
|
|
|
/// Describes a overview of a individual package.
|
|
|
|
#[derive(Deserialize, Serialize, Clone)]
|
|
|
|
pub struct PackageDescription {
|
2018-01-27 11:58:56 +00:00
|
|
|
pub name: String,
|
|
|
|
pub description: String,
|
|
|
|
pub default: Option<bool>,
|
2018-01-27 03:27:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Describes the application itself.
|
|
|
|
#[derive(Deserialize, Serialize, Clone)]
|
|
|
|
pub struct GeneralConfig {
|
2018-01-27 11:58:56 +00:00
|
|
|
pub name: String,
|
|
|
|
pub installing_message: String,
|
2018-01-27 03:27:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Clone)]
|
|
|
|
pub struct Config {
|
2018-01-27 11:58:56 +00:00
|
|
|
pub general: GeneralConfig,
|
|
|
|
pub packages: Vec<PackageDescription>,
|
2018-01-27 03:27:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Config {
|
|
|
|
/// Serialises as a JSON string.
|
|
|
|
pub fn to_json_str(&self) -> Result<String, SerdeError> {
|
|
|
|
serde_json::to_string(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Builds a configuration from a specified TOML string.
|
2018-01-27 11:58:56 +00:00
|
|
|
pub fn from_toml_str(contents: &str) -> Result<Self, TomlError> {
|
2018-01-27 03:27:41 +00:00
|
|
|
toml::from_str(contents)
|
|
|
|
}
|
|
|
|
}
|