feat: write some cdylib code
This commit is contained in:
@@ -4,6 +4,7 @@ use thiserror::Error as TeError;
|
||||
|
||||
mod last_error;
|
||||
mod string_cache;
|
||||
mod wrapper;
|
||||
|
||||
// region: Error
|
||||
|
||||
|
||||
83
wfassoc_cdylib/src/wrapper.rs
Normal file
83
wfassoc_cdylib/src/wrapper.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use thiserror::Error as TeError;
|
||||
|
||||
/// Error occurs in this module.
|
||||
#[derive(Debug, TeError)]
|
||||
pub enum Error {}
|
||||
|
||||
/// Result type used in this module.
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Schema is the sketchpad of complete Program.
|
||||
///
|
||||
/// We will create a Schema first, fill some properties, add file extensions,
|
||||
/// then convert it into immutable Program for following using.
|
||||
#[derive(Debug)]
|
||||
pub struct Schema {
|
||||
identifier: String,
|
||||
path: String,
|
||||
clsid: String,
|
||||
icons: HashMap<String, String>,
|
||||
behaviors: HashMap<String, String>,
|
||||
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 {
|
||||
identifier: String::new(),
|
||||
path: String::new(),
|
||||
clsid: String::new(),
|
||||
icons: HashMap::new(),
|
||||
behaviors: HashMap::new(),
|
||||
exts: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_identifier(&mut self, identifier: &str) -> Result<()> {}
|
||||
|
||||
pub fn set_path(&mut self, exe_path: &str) -> Result<()> {}
|
||||
|
||||
pub fn set_clsid(&mut self, clsid: &str) -> Result<()> {}
|
||||
|
||||
pub fn add_icon(&mut self, name: &str, value: &str) -> Result<()> {}
|
||||
|
||||
pub fn add_behavior(&mut self, name: &str, value: &str) -> Result<()> {}
|
||||
|
||||
pub fn add_ext(
|
||||
&mut self,
|
||||
ext: &str,
|
||||
ext_name: &str,
|
||||
ext_icon: &str,
|
||||
ext_behavior: &str,
|
||||
) -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn into_program(self) -> Result<Program> {
|
||||
Program::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Program is a complete and immutable program representer
|
||||
pub struct Program {}
|
||||
|
||||
impl TryFrom<Schema> for Program {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: Schema) -> std::result::Result<Self, Self::Error> {
|
||||
Self::new(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl Program {
|
||||
pub fn new(schema: Schema) -> Result<Self> {}
|
||||
}
|
||||
Reference in New Issue
Block a user