1
0

feat: finish manifest convertion

This commit is contained in:
2026-04-17 15:43:39 +08:00
parent a7a9a71e80
commit c650290df6
2 changed files with 88 additions and 21 deletions

View File

@@ -8,7 +8,10 @@ pub use lowlevel::{Scope, View};
/// Error occurs when operating with `Schema`.
#[derive(Debug, TeError)]
pub enum SchemaError {}
pub enum SchemaError {
#[error("duplicate key: {0}")]
DuplicateKey(String),
}
/// Error occurs when trying converting `Schema` into `Program`.
#[derive(Debug, TeError)]
@@ -40,14 +43,6 @@ pub struct Schema {
exts: HashMap<String, SchemaExt>,
}
/// Internal used struct as the Schema file extensions hashmap value type.
#[derive(Debug)]
struct SchemaExt {
name: String,
icon: String,
behavior: String,
}
impl Schema {
pub fn new() -> Self {
Self {
@@ -64,24 +59,49 @@ impl Schema {
}
}
pub fn set_identifier(&mut self, identifier: &str) -> Result<(), SchemaError> {
todo!()
pub fn set_identifier(&mut self, identifier: &str) -> () {
self.identifier = identifier.to_string();
}
pub fn set_path(&mut self, exe_path: &str) -> Result<(), SchemaError> {
todo!()
pub fn set_path(&mut self, exe_path: &str) -> () {
self.path = exe_path.to_string();
}
pub fn set_clsid(&mut self, clsid: &str) -> Result<(), SchemaError> {
todo!()
pub fn set_clsid(&mut self, clsid: &str) -> () {
self.clsid = clsid.to_string();
}
pub fn set_name(&mut self, name: Option<&str>) -> () {
self.name = name.map(|n| n.to_string());
}
pub fn set_icon(&mut self, icon: Option<&str>) -> () {
self.icon = icon.map(|i| i.to_string());
}
pub fn set_behavior(&mut self, behavior: Option<&str>) -> () {
self.behavior = behavior.map(|b| b.to_string());
}
pub fn add_str(&mut self, name: &str, value: &str) -> Result<(), SchemaError> {
match self.strs.insert(name.to_string(), value.to_string()) {
Some(_) => Err(SchemaError::DuplicateKey(name.to_string())),
None => Ok(()),
}
}
pub fn add_icon(&mut self, name: &str, value: &str) -> Result<(), SchemaError> {
todo!()
match self.icons.insert(name.to_string(), value.to_string()) {
Some(_) => Err(SchemaError::DuplicateKey(name.to_string())),
None => Ok(()),
}
}
pub fn add_behavior(&mut self, name: &str, value: &str) -> Result<(), SchemaError> {
todo!()
match self.behaviors.insert(name.to_string(), value.to_string()) {
Some(_) => Err(SchemaError::DuplicateKey(name.to_string())),
None => Ok(()),
}
}
pub fn add_ext(
@@ -91,7 +111,13 @@ impl Schema {
ext_icon: &str,
ext_behavior: &str,
) -> Result<(), SchemaError> {
todo!()
match self.exts.insert(
ext.to_string(),
SchemaExt::new(ext_name, ext_icon, ext_behavior),
) {
Some(_) => Err(SchemaError::DuplicateKey(ext.to_string())),
None => Ok(()),
}
}
pub fn into_program(self) -> Result<Program, ParseProgramError> {
@@ -99,6 +125,24 @@ impl Schema {
}
}
/// Internal used struct as the Schema file extensions hashmap value type.
#[derive(Debug)]
struct SchemaExt {
name: String,
icon: String,
behavior: String,
}
impl SchemaExt {
fn new(name: &str, icon: &str, behavior: &str) -> Self {
Self {
name: name.to_string(),
icon: icon.to_string(),
behavior: behavior.to_string(),
}
}
}
/// Program is a complete and immutable program representer
pub struct Program {}