use serde::Deserialize; use std::collections::HashMap; use std::path::Path; use thiserror::Error as TeError; use toml; /// Error occurs in this module. #[derive(Debug, TeError)] pub enum Error { /// Io error #[error("IO error when reading manifest file")] Io(#[from] std::io::Error), /// Toml deserialization error #[error("given TOML manifest file has bad format")] Toml(#[from] toml::de::Error), } /// Result type used in this module. type Result = std::result::Result; // region: Raw Manifest /// Raw user input manifest. /// /// This manifest is the raw input of user. /// Some fields may not be checked due to user invalid input. #[derive(Debug, Deserialize)] pub struct RawManifest { identifier: String, path: String, clsid: String, icons: HashMap, behaviors: HashMap, exts: HashMap, } impl RawManifest { pub fn into_checked(&self) -> Result { todo!() } } /// The sub-type in raw user input manifest. #[derive(Debug, Deserialize)] pub struct RawManifestExt { name: String, icon: String, behavior: String, } impl RawManifestExt { pub fn into_checked(&self) -> Result { todo!() } } impl RawManifest { /// Read raw user manifest. pub fn from_file(path: &Path) -> Result { let contents = std::fs::read_to_string(path)?; let config: RawManifest = toml::from_str(&contents)?; Ok(config) } } // endregion // region: Checked Manifest /// Converted user input manifest. /// /// This manifest struct is prepared for final use. /// All fields loacted in this struct is checked and ready to be used. #[derive(Debug)] pub struct Manifest { } impl Manifest { } pub struct ManifestExt { } impl ManifestExt { } // endregion