1
0
Files
wfassoc/wfassoc_exec/src/manifest.rs

91 lines
1.7 KiB
Rust
Raw Normal View History

2025-10-17 14:19:26 +08:00
use serde::Deserialize;
use std::collections::HashMap;
2025-12-30 23:21:01 +08:00
use std::path::Path;
2025-10-17 14:19:26 +08:00
use thiserror::Error as TeError;
use toml;
2025-12-30 23:21:01 +08:00
/// Error occurs in this module.
2025-10-17 14:19:26 +08:00
#[derive(Debug, TeError)]
#[error("{0}")]
pub enum Error {
2025-12-30 23:21:01 +08:00
/// Io error
2025-10-17 14:19:26 +08:00
Io(#[from] std::io::Error),
2025-12-30 23:21:01 +08:00
/// Toml deserialization error
2025-10-17 14:19:26 +08:00
Toml(#[from] toml::de::Error),
}
2025-12-30 23:21:01 +08:00
/// Result type used in this module.
type Result<T> = std::result::Result<T, Error>;
2025-10-17 14:19:26 +08:00
2025-12-30 23:21:01 +08:00
// 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.
2025-10-17 14:19:26 +08:00
#[derive(Debug, Deserialize)]
2025-12-30 23:21:01 +08:00
pub struct RawManifest {
identifier: String,
path: String,
clsid: String,
icons: HashMap<String, String>,
behaviors: HashMap<String, String>,
exts: HashMap<String, RawManifestExt>,
2025-10-17 14:19:26 +08:00
}
2025-12-30 23:21:01 +08:00
impl RawManifest {
pub fn into_checked(&self) -> Result<Manifest> {
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<ManifestExt> {
todo!()
}
}
impl RawManifest {
/// Read raw user manifest.
pub fn from_file(path: &Path) -> Result<RawManifest> {
2025-10-17 14:19:26 +08:00
let contents = std::fs::read_to_string(path)?;
2025-12-30 23:21:01 +08:00
let config: RawManifest = toml::from_str(&contents)?;
2025-10-17 14:19:26 +08:00
Ok(config)
}
2025-12-30 23:21:01 +08:00
}
// 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