summaryrefslogtreecommitdiff
path: root/mingling/src/asset
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-28 00:47:46 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-28 00:47:46 +0800
commit7ce68cd11516bd7cf037ecea99a92aee7c31b2c3 (patch)
treea3923ad41c91aa21fe169fd6b4b1bf8898a82589 /mingling/src/asset
Add initial Mingling framework codebase
Diffstat (limited to 'mingling/src/asset')
-rw-r--r--mingling/src/asset/chain.rs8
-rw-r--r--mingling/src/asset/chain/error.rs13
-rw-r--r--mingling/src/asset/dispatcher.rs19
-rw-r--r--mingling/src/asset/node.rs54
-rw-r--r--mingling/src/asset/renderer.rs6
5 files changed, 100 insertions, 0 deletions
diff --git a/mingling/src/asset/chain.rs b/mingling/src/asset/chain.rs
new file mode 100644
index 0000000..1ea1125
--- /dev/null
+++ b/mingling/src/asset/chain.rs
@@ -0,0 +1,8 @@
+use crate::ChainProcess;
+
+pub mod error;
+
+pub trait Chain {
+ type Previous;
+ fn proc(p: Self::Previous) -> impl Future<Output = ChainProcess> + Send;
+}
diff --git a/mingling/src/asset/chain/error.rs b/mingling/src/asset/chain/error.rs
new file mode 100644
index 0000000..d4da4ac
--- /dev/null
+++ b/mingling/src/asset/chain/error.rs
@@ -0,0 +1,13 @@
+use crate::AnyOutput;
+
+#[derive(thiserror::Error, Debug)]
+pub enum ChainProcessError {
+ #[error("Other error: {0}")]
+ Other(String),
+
+ #[error("IO error: {0}")]
+ IO(#[from] std::io::Error),
+
+ #[error("Broken chain")]
+ Broken(AnyOutput),
+}
diff --git a/mingling/src/asset/dispatcher.rs b/mingling/src/asset/dispatcher.rs
new file mode 100644
index 0000000..31623d3
--- /dev/null
+++ b/mingling/src/asset/dispatcher.rs
@@ -0,0 +1,19 @@
+use crate::{ChainProcess, Program, asset::node::Node};
+
+pub use mingling_macros::Dispatcher;
+
+pub trait Dispatcher {
+ fn node(&self) -> Node;
+}
+
+pub trait DispatcherChain {
+ fn begin(&self) -> ChainProcess;
+}
+
+impl Program {
+ /// Adds a dispatcher to the program.
+ pub fn with_dispatcher<D: Dispatcher + 'static>(&mut self, dispatcher: D) {
+ let dispatcher = Box::new(dispatcher);
+ self.dispatcher.push(dispatcher);
+ }
+}
diff --git a/mingling/src/asset/node.rs b/mingling/src/asset/node.rs
new file mode 100644
index 0000000..c8b7600
--- /dev/null
+++ b/mingling/src/asset/node.rs
@@ -0,0 +1,54 @@
+use just_fmt::kebab_case;
+
+#[derive(Debug, Default)]
+pub struct Node {
+ node: Vec<String>,
+}
+
+impl Node {
+ pub fn join(self, node: impl Into<String>) -> Node {
+ let mut new_node = self.node;
+ new_node.push(node.into());
+ Node { node: new_node }
+ }
+}
+
+impl From<&str> for Node {
+ fn from(s: &str) -> Self {
+ let node = s.split('.').map(|part| kebab_case!(part)).collect();
+ Node { node }
+ }
+}
+
+impl From<String> for Node {
+ fn from(s: String) -> Self {
+ let node = s.split('.').map(|part| kebab_case!(part)).collect();
+ Node { node }
+ }
+}
+
+impl PartialEq for Node {
+ fn eq(&self, other: &Self) -> bool {
+ self.node == other.node
+ }
+}
+
+impl Eq for Node {}
+
+impl PartialOrd for Node {
+ fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl Ord for Node {
+ fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+ self.node.cmp(&other.node)
+ }
+}
+
+impl std::fmt::Display for Node {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{}", self.node.join("."))
+ }
+}
diff --git a/mingling/src/asset/renderer.rs b/mingling/src/asset/renderer.rs
new file mode 100644
index 0000000..3852b55
--- /dev/null
+++ b/mingling/src/asset/renderer.rs
@@ -0,0 +1,6 @@
+use crate::RenderResult;
+
+pub trait Renderer {
+ type Previous;
+ fn render(p: Self::Previous, r: &mut RenderResult);
+}