From 778f713b2c4b8f8311daf2b878de91e449f69988 Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Tue, 25 Nov 2025 16:50:59 +0300 Subject: Created minimal package validation here. Writed documentations comments (///) --- src/cfg/config.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/cfg') diff --git a/src/cfg/config.rs b/src/cfg/config.rs index 45be37d..8672433 100644 --- a/src/cfg/config.rs +++ b/src/cfg/config.rs @@ -13,39 +13,45 @@ pub enum Loglevel { Error } + +/// `mesk.toml` configuration fields here #[derive(Deserialize, Debug, Serialize)] pub struct Config { - repo: Repo, - log: Log, - paths: Paths, + pub repo: Repo, + pub log: Log, + pub paths: Paths, } #[derive(Deserialize, Debug, Serialize)] pub struct Log { #[serde(rename = "log_file")] - log_file: String, + pub log_file: String, #[serde(rename = "log_level")] - log_level: Loglevel, + pub log_level: Loglevel, } // Rename needed for editing mesk.toml file fields but dont touch code. #[derive(Deserialize, Debug, Serialize)] pub struct Repo { #[serde(rename = "repo_url")] - repo_url: String, + pub repo_url: String, #[serde(rename = "auto_update")] - auto_update: bool, + pub auto_update: bool, } #[derive(Deserialize, Debug, Serialize)] pub struct Paths { #[serde(rename = "cache_dir")] - cache_dir: String, + pub cache_dir: String, #[serde(rename = "build_dir")] - build_dir: String, + pub build_dir: String, } impl Config { + + /// Parse the /etc/mesk.toml file and return the Config object. + /// + /// This function reads the /etc/mesk.toml file, parses it and returns the Config object. pub fn parse() -> Result { let contents = fs::read_to_string("/etc/mesk.toml").unwrap(); let result: Config = toml::from_str(&contents)?; @@ -53,6 +59,9 @@ impl Config { } + /// Return the default configuration as a toml string. + /// + /// This function returns the default configuration as a toml string. pub fn default() -> Result { let default: Config = Config { repo: Repo { -- cgit v1.2.3